Jump to content
Sign in to follow this  
shai

help in StringRegExpReplace

Recommended Posts

shai

i have encrypted string.

i want convert this string to normal string.

this is a encryption Key:

'$"' = '1'
'$#' = '2'
'$$' = '3'
'$%' = '4'
'$&' = '5'
'$'' = '6'
'$(' = '7'
'$)' = '8'
'$*' = '9'
'$!' = '0'
'&0' = '_'
'#.' = '-'
'#/' = '.'
''"' = 'a'
''#' = 'b'
''$' = 'c'
''%' = 'd'
''&' = 'e'
'''' = 'f'
''(' = 'g'
'')' = 'h'
''*' = 'i'
''+' = 'j'
'',' = 'k'
''-' = 'l'
''.' = 'm'
''/' = 'n'
''0' = 'o'
'(!' = 'p'
'("' = 'q'
'(#' = 'r'
'($' = 's'
'(%' = 't'
'(&' = 'u'
"('" = 'v'
'((' = 'w'
'()' = 'x'
'(*' = 'y'
'(+' = 'z'

for example if i have this string:

'"(&(%'0'*(%

i want convret to "aotuit"

thanks

Share this post


Link to post
Share on other sites
shai

by now i using this code to split the string:

#include <Array.au3>

_ArrayDisplay(_StringChop('$"$!$#$!$$$!',2))

Func _StringChop($string, $size)
    
$count = Ceiling(StringLen($string)/$size)
Dim $array[$count+1], $start = 1
For $i = 1 To $count
    $array[$i] = StringMid($string, $start, $size)
    $start += $size
Next
$array[0] = $count
Return $array
EndFunc

but i dont know how i can convert it

Share this post


Link to post
Share on other sites
Malkey

Try this.

; Substitution cipher
Local $aArray[39][2] = [['$"', '1'],['$#', '2'],['$$', '3'],['$%', '4'],['$&', '5'],["$'", '6'],['$(', '7'], _
        ['$)', '8'],['$*', '9'],['$!', '0'],['&0', '_'],['#.', '-'],['#/', '.'],['''"', 'a'],['''#', 'b'], _
        ['''$', 'c'],['''%', 'd'],['''&', 'e'],["''", 'f'],["'(", 'g'],["')", 'h'],["'*", 'i'],["'+", 'j'], _
        ["',", 'k'],["'-", 'l'],["'.", 'm'],["'/", 'n'],["'0", 'o'],["(!", 'p'],['("', 'q'],['(#', 'r'], _
        ['($', 's'],['(%', 't'],['(&', 'u'],["('", 'v'],['((', 'w'],['()', 'x'],['(*', 'y'],['(+', 'z']]

Local $sEncrypted = "'""(&(%'0'*(%"
Local $sDecrypted = _Decrypt($sEncrypted)
MsgBox(0, "Decryption", "Code: " & $sEncrypted & @CRLF & "Uncoded: " & $sDecrypted)

Local $sText = "AutoIt"
Local $sEncoded = _Encrypt($sText)
MsgBox(0, "Encryption", "Text: " & $sText & @CRLF & "Coded: " & $sEncoded)


Func _Decrypt($string)
    Local $aEncryped = StringRegExp($string, "(..)", 3)
    Local $sRet = ""
    For $i = 0 To UBound($aEncryped) - 1
        For $iF = 0 To UBound($aArray) - 1
            If $aArray[$iF][0] = $aEncryped[$i] Then $sRet &= $aArray[$iF][1]
        Next
    Next
    Return $sRet
EndFunc   ;==>_Decrypt

Func _Encrypt($string)
    Local $aDecryped = StringSplit(StringLower($string), "", 2)
    Local $sRet = ""
    For $i = 0 To UBound($aDecryped) - 1
        For $iF = 0 To UBound($aArray) - 1
            If $aArray[$iF][1] = $aDecryped[$i] Then $sRet &= $aArray[$iF][0]
        Next
    Next
    Return $sRet
EndFunc   ;==>_Encrypt

Share this post


Link to post
Share on other sites
shai

its perfect.

thanks for your help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×