请教关于字符串加密的问题?
大家对含有中文的字符串都用什么加密,试了好几个都在解码的时候出现乱码?谁有现成的函数,给我一个,谢谢! http://www.autoitx.com/forum.php?mod=viewthread&tid=14189&highlight=%BC%D3%C3%DC 回复 2# whitehead用过,写的不错,但还是不理想 #include <Crypt.au3>
Local Const $sUserKey = "CryptPassword" ; Declare a password string to decrypt/encrypt the data.
Local $sData = "请教关于字符串加密的问题" ; Data that will be encrypted.
Local $bEncrypted = _Crypt_EncryptData(StringToBinary ($sData) , $sUserKey, $CALG_RC4) ; Encrypt the data using the generic password string.
$bEncrypted = _Crypt_DecryptData($bEncrypted, $sUserKey, $CALG_RC4) ; Decrypt the data using the generic password string. The return value is a binary string.
MsgBox(4096, "Decrypted data", BinaryToString($bEncrypted)) ; Convert the binary string using BinaryToString to display the initial data we encrypted. 哪方面不理想? 学习了,谢谢4楼提供的方法 Local $password = _JiaMi("我是密码?")
MsgBox(262144,'加密后的密码:',$password)
Local $origial = _JieMi($password)
MsgBox(262144,'解密后的原密码:',$origial)
Func _JiaMi($iPassword)
Local $b = "", $e = ""
Local $e = $iPassword
$iPassword = ""
Local $f = 0
While StringLen($e) <> $f
$f += 1
$buffer = StringToBinary(StringMid($e, $f, 1))
$buffer = StringRight($buffer, StringLen($buffer) - 2)
If StringLen($buffer) = 2 Then
$iPassword = $iPassword & ChrW(Dec($buffer))
Else
$iPassword = $iPassword & ChrW(Dec(StringLeft($buffer, 2))) & ChrW(Dec(StringRight($buffer, 2)))
EndIf
WEnd
While StringLen($iPassword) <> Int(StringLen($iPassword) / 3) * 3
$iPassword = $iPassword & " "
WEnd
For $i = 1 To StringLen($iPassword) / 3
$c = 0
For $j = 1 To 3
$c += AscW(StringMid($iPassword, ($i - 1) * 3 + $j, 1)) * (256 ^ (3 - $j))
Next
For $j = 1 To 4
$d = Int($c / (64 ^ (4 - $j)))
$c = $c - $d * (64 ^ (4 - $j))
$b = $b & _code($d)
Next
Next
If StringLen($b) <= 240 Then
ClipPut($b)
Return $b
Else
Return SetError(-1)
EndIf
EndFunc ;==>_JiaMi
Func _code($z)
Local $y
If $z < 26 Then
$y = ChrW($z + 65)
Else
If $z < 52 Then
$y = ChrW($z + 71)
Else
If $z < 62 Then
$y = ChrW($z - 4)
Else
If $z = 62 Then
$y = "-"
Else
$y = "_"
EndIf
EndIf
EndIf
EndIf
Return $y
EndFunc ;==>_code
Func _JieMi($a)
Local $e = "", $f = ""
For $i = 1 To StringLen($a) / 4
$c = 0
For $j = 1 To 4
$b = StringMid($a, ($i - 1) * 4 + $j, 1)
$c = $c + num($b) * (64 ^ (4 - $j))
Next
For $j = 1 To 3
$d = Int($c / (256 ^ (3 - $j)))
$c = $c - $d * (256 ^ (3 - $j))
$e = $e & ChrW($d)
Next
Next
$f = $e
$e = ""
For $i = 1 To StringLen($f)
If AscW(StringMid($f, $i, 1)) < 129 Then
$e = $e & StringMid($f, $i, 1)
Else
$j = "0x" & StringRight(Hex(AscW(StringMid($f, $i, 1))), 2) & StringRight(Hex(AscW(StringMid($f, $i + 1, 1))), 2)
$e = $e & BinaryToString($j)
$i += 1
EndIf
Next
Return $e
EndFunc ;==>_JieMi
Func num($z)
Local $y, $x
$y = AscW($z)
If $z = "-" Then
$x = 62
Else
If $z = "_" Then
$x = 63
Else
If $y < 58 Then
$x = $y + 4
Else
If $y < 91 Then
$x = $y - 65
Else
$x = $y - 71
EndIf
EndIf
EndIf
EndIf
Return $x
EndFunc ;==>num
回复 1# glsanshi
页:
[1]