4月112015
Au3差异加密
原创作者:tvzml
一直以来想给密码加密,现成的加密代码为一些简单的密码,如 就一个 1 ,加密以后的密文也很简单,很容易被猜出来,苦思冥想之后,巧妙的使用了一种随机差异加密,可以使用加密后的结果千变万化,而且加密以后的长度也是比较简洁,可以达到事半功倍的效果,你花1倍功力打乱规律,破解者可能要花10倍的功力是分析规律,想通过密文反推密码难度很大,以下代码是经过1次打乱的代码:
第1次运行
第2次运行
code----------------------------
#include <String.au3> #include <Array.au3> Local $String = "123 ABC 中国" Local $Hex16 = __R16Encode($String) MsgBox(4096, "R16加密", "加密前: " & $String & @LF & "加密后: " & $Hex16) Local $String = __R16Decode($Hex16) MsgBox(4096, "R16加密", "解密前: " & $Hex16 & @LF & "解密后: " & $String) Exit Func __R16Encode($STR = '') Dim $Y16[16] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] Dim $R16[16] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] Dim $R16_D, $R16STR, $Hex, $ii, $STR_Tmp_Dat, $STR_Tmp For $i = 0 To UBound($R16) - 1 $R16_D = Random($i, UBound($R16) - 1, 1) _ArraySwap($R16[$i], $R16[$R16_D]) Next $R16STR = StringReplace(_ArrayToString($R16), '|', '') $Hex = _StringToHex($STR) Dim $Str_Len = StringLen($Hex) For $i = 1 To $Str_Len Dim $editstr = StringMid($Hex, $i, 1) For $ii = 0 To 15 $STR_Tmp = StringReplace($editstr, $Y16[$ii], $R16[$ii]) If @extended = 1 Then ExitLoop Next $STR_Tmp_Dat &= $STR_Tmp Next If $STR_Tmp_Dat <> "" Then $STR_Tmp_Dat = StringRight($R16STR, 8) & $STR_Tmp_Dat & StringLeft($R16STR, 8) Return $STR_Tmp_Dat EndFunc ;==>__R16Encode Func __R16Decode($STR = '') If StringLen($STR) < 17 Then Return "" Dim $Y16[16] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] Dim $R16_CODE_L = StringRight($STR, 8) Dim $R16_CODE_R = StringLeft($STR, 8) Dim $R16_CODE = $R16_CODE_L & $R16_CODE_R Dim $R16 = StringSplit($R16_CODE, '') _ArrayDelete($R16, 0) Dim $Hex, $ii, $STR_Tmp_Dat, $STR_Tmp $Hex = StringTrimLeft($STR, 8) $Hex = StringTrimRight($Hex, 8) Dim $Str_Len = StringLen($Hex) For $i = 1 To $Str_Len Dim $editstr = StringMid($Hex, $i, 1) For $ii = 0 To 15 $STR_Tmp = StringReplace($editstr, $R16[$ii], $Y16[$ii]) If @extended = 1 Then ExitLoop Next $STR_Tmp_Dat &= $STR_Tmp Next $Hex = _HexToString($STR_Tmp_Dat) Return $Hex EndFunc ;==>__R16Decode```
本文固定链接: http://jianyiit.com/post-85.html
扫描二维码,在手机上阅读
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!
大人,您好!
第30行出错:_ArraySwap($R16[$i], $R16[$R16_D])这一行,我查了帮助,多加了一个参数,但每次加密后的结果都是一样的,请楼主看一下呢?谢谢!
@蝶舞:第15行_ArraySwap($R16[$i], $R16[$R16_D])改为_ArraySwap($R16,$R16[$i], $R16[$R16_D])