找回密码
 加入
搜索
查看: 4208|回复: 9

[系统综合] Md5函数

  [复制链接]
发表于 2011-5-2 11:23:13 | 显示全部楼层 |阅读模式
本帖最后由 xlbcwn 于 2011-7-10 10:17 编辑

我做了一个Md5的加密函数,可为什么加密后输出的不对?(其中from10、to10、xput为进制转换函数)
#include "huansuan.au3"
#include <Array.au3>
MsgBox(0,"",Md5("a"))

Func Md5($string)
        ;Local $a1 = 0x01234567,$b1 = 0x89abcdef,$c1 = 0xfedcba98,$d1 = 0x76543210
        ;Local $a = 0x01234567,$b = 0x89abcdef,$c = 0xfedcba98,$d = 0x76543210
        Local $a1 = 19088743,$b1 = 2309737967,$c1 = 4275878552,$d1 = 1985229328
        Local $a = 19088743,$b = 2309737967,$c = 4275878552,$d = 1985229328
        If Not (StringToBinary($string) = "") Then
                Local $msga = xput(StringTrimLeft(StringToBinary($string,4),2),16,2)
        Else
                Local $msga = 0
        EndIf
        While Mod(StringLen($msga),8)
                $msga = "0" & $msga
        WEnd
        Local $weishu = from10(StringLen($msga),2)
        $msga &= 1
        While Not (Mod(StringLen($msga),512) = 448)
                $msga &= 0
        WEnd
        While StringLen($weishu) < 64
                $weishu = 0 & $weishu
        WEnd
        $msga &= $weishu
        Local $cishu = StringLen($msga) / 512
        Local $msg[$cishu][16]
        For $bianliang1 = 0 To $cishu - 1
                For $bianliang2 = 0 To 15
                        $msg[$bianliang1][$bianliang2] = to10(StringLeft($msga,32),2)
                        $msga = StringTrimLeft($msga,32)
                Next
        Next
        _ArrayDisplay($msg)

        For $bianliang = 0 To $cishu - 1
                $a = FF($a,$b,$c,$d,$msg[$bianliang][0],7,3614090360)
                $d = FF($d,$a,$b,$c,$msg[$bianliang][1],12,3905402710)
                $c = FF($c,$d,$a,$b,$msg[$bianliang][2],17,606105819)
                $b = FF($b,$c,$d,$a,$msg[$bianliang][3],22,3250441966)
                $a = FF($a,$b,$c,$d,$msg[$bianliang][4],7,4118548399)
                $d = FF($d,$a,$b,$c,$msg[$bianliang][5],12,1200080426)
                $c = FF($c,$d,$a,$b,$msg[$bianliang][6],17,2821735955)
                $b = FF($b,$c,$d,$a,$msg[$bianliang][7],22,4249261313)
                $a = FF($a,$b,$c,$d,$msg[$bianliang][8],7,1770035416)
                $d = FF($d,$a,$b,$c,$msg[$bianliang][9],12,2336552879)
                $c = FF($c,$d,$a,$b,$msg[$bianliang][10],17,4294925233)
                $b = FF($b,$c,$d,$a,$msg[$bianliang][11],22,2304563134)
                $a = FF($a,$b,$c,$d,$msg[$bianliang][12],7,1804603682)
                $d = FF($d,$a,$b,$c,$msg[$bianliang][13],12,4254626195)
                $c = FF($c,$d,$a,$b,$msg[$bianliang][14],17,2792965006)
                $b = FF($b,$c,$d,$a,$msg[$bianliang][15],22,1236535329)

                $a = GG($a,$b,$c,$d,$msg[$bianliang][1],5,4129170786)
                $d = GG($d,$a,$b,$c,$msg[$bianliang][6],9,3225465664)
                $c = GG($c,$d,$a,$b,$msg[$bianliang][11],14,643717713)
                $b = GG($b,$c,$d,$a,$msg[$bianliang][0],20,3921069994)
                $a = GG($a,$b,$c,$d,$msg[$bianliang][5],5,3593408605)
                $d = GG($d,$a,$b,$c,$msg[$bianliang][10],9,38016083)
                $c = GG($c,$d,$a,$b,$msg[$bianliang][15],14,3634488961)
                $b = GG($b,$c,$d,$a,$msg[$bianliang][4],20,3889429448)
                $a = GG($a,$b,$c,$d,$msg[$bianliang][9],5,568446438)
                $d = GG($d,$a,$b,$c,$msg[$bianliang][14],9,3275163606)
                $c = GG($c,$d,$a,$b,$msg[$bianliang][3],14,4107603335)
                $b = GG($b,$c,$d,$a,$msg[$bianliang][8],20,1163531501)
                $a = GG($a,$b,$c,$d,$msg[$bianliang][13],5,2850285829)
                $d = GG($d,$a,$b,$c,$msg[$bianliang][2],9,4243563512)
                $c = GG($c,$d,$a,$b,$msg[$bianliang][7],14,1735328473)
                $b = GG($b,$c,$d,$a,$msg[$bianliang][12],20,2368359562)

                $a = HH($a,$b,$c,$d,$msg[$bianliang][5],4,4294588738)
                $d = HH($d,$a,$b,$c,$msg[$bianliang][8],11,2272392833)
                $c = HH($c,$d,$a,$b,$msg[$bianliang][11],16,1839030562)
                $b = HH($b,$c,$d,$a,$msg[$bianliang][14],23,4259657740)
                $a = HH($a,$b,$c,$d,$msg[$bianliang][1],4,2763975236)
                $d = HH($d,$a,$b,$c,$msg[$bianliang][4],11,1272893353)
                $c = HH($c,$d,$a,$b,$msg[$bianliang][7],16,4139469664)
                $b = HH($b,$c,$d,$a,$msg[$bianliang][10],23,3200236656)
                $a = HH($a,$b,$c,$d,$msg[$bianliang][13],4,681279174)
                $d = HH($d,$a,$b,$c,$msg[$bianliang][0],11,3936430074)
                $c = HH($c,$d,$a,$b,$msg[$bianliang][3],16,3572445317)
                $b = HH($b,$c,$d,$a,$msg[$bianliang][6],23,76029189)
                $a = HH($a,$b,$c,$d,$msg[$bianliang][9],4,3654602809)
                $d = HH($d,$a,$b,$c,$msg[$bianliang][12],11,3873151461)
                $c = HH($c,$d,$a,$b,$msg[$bianliang][15],16,530742520)
                $b = HH($b,$c,$d,$a,$msg[$bianliang][2],23,3299628645)

                $a = II($a,$b,$c,$d,$msg[$bianliang][0],6,4096336452)
                $d = II($d,$a,$b,$c,$msg[$bianliang][7],10,1126891415)
                $c = II($c,$d,$a,$b,$msg[$bianliang][14],15,2878612391)
                $b = II($b,$c,$d,$a,$msg[$bianliang][5],21,4237533241)
                $a = II($a,$b,$c,$d,$msg[$bianliang][12],6,1700485571)
                $d = II($d,$a,$b,$c,$msg[$bianliang][3],10,2399980690)
                $c = II($c,$d,$a,$b,$msg[$bianliang][10],15,4293915773)
                $b = II($b,$c,$d,$a,$msg[$bianliang][1],21,2240044497)
                $a = II($a,$b,$c,$d,$msg[$bianliang][8],6,1873313359)
                $d = II($d,$a,$b,$c,$msg[$bianliang][15],10,4264355552)
                $c = II($c,$d,$a,$b,$msg[$bianliang][6],15,2734768916)
                $b = II($b,$c,$d,$a,$msg[$bianliang][13],21,1309151649)
                $a = II($a,$b,$c,$d,$msg[$bianliang][4],6,4149444226)
                $d = II($d,$a,$b,$c,$msg[$bianliang][11],10,3174756917)
                $c = II($c,$d,$a,$b,$msg[$bianliang][2],15,718787259)
                $b = II($b,$c,$d,$a,$msg[$bianliang][9],21,3951481745)

                $a1 += $a
                $b1 += $b
                $c1 += $c
                $d1 += $d
                ;$a = $a1
                ;$b = $b1
                ;$c = $c1
                ;$d = $d1
        Next
        ;Return from10($a1 + $b1 + $c1 + $d1,16)
        ;Return $a1 & " " & $b1 & " " & $c1 & " " & $d1
        Return from10($a1,16) & from10($b1,16) & from10($c1,16) & from10($d1,16)
EndFunc

Func F($x,$y,$z)
        Return BitOR(BitAND($x,$y),BitAND(BitNOT($x),$z))
EndFunc

Func G($x,$y,$z)
        Return BitOR(BitAND($x,$z),BitAND($y,BitNOT($z)))
EndFunc

Func H($x,$y,$z)
        Return BitXOR($x,$y,$z)
EndFunc

Func I($x,$y,$z)
        Return BitXOR($y,BitOR($x,BitNOT($z)))
EndFunc

Func FF($a,$b,$c,$d,$Mj,$s,$ti)
        Return $b + zuoyi(($a + F($b,$c,$d) + $Mj + $ti),$s)
EndFunc

Func GG($a,$b,$c,$d,$Mj,$s,$ti)
        Return $b + zuoyi(($a + G($b,$c,$d) + $Mj + $ti),$s)
EndFunc

Func HH($a,$b,$c,$d,$Mj,$s,$ti)
        Return $b + zuoyi(($a + H($b,$c,$d) + $Mj + $ti),$s)
EndFunc

Func II($a,$b,$c,$d,$Mj,$s,$ti)
        Return $b + zuoyi(($a + I($b,$c,$d) + $Mj + $ti),$s)
EndFunc

Func zuoyi($m,$n)
        Return BitRotate($m,$n,"D")
        ;Return BitShift($m,-$n)
EndFunc
发表于 2011-5-2 16:41:19 | 显示全部楼层
本帖最后由 lpxx 于 2011-5-2 16:42 编辑
#include "huansuan.au3"
au3没这种写法。

加密可以直接用官方的
#include <ACN_HASH.au3>
MsgBox(0, "", _MD5("a"))
 楼主| 发表于 2011-5-2 17:04:17 | 显示全部楼层
有这个函数?
 楼主| 发表于 2011-5-2 17:19:33 | 显示全部楼层
在哪下载呢?
发表于 2011-5-2 17:55:26 | 显示全部楼层
中文版au3里面包含了ACN_HASH.au3
发表于 2011-5-2 17:55:46 | 显示全部楼层
中文版au3里面包含了ACN_HASH.au3
 楼主| 发表于 2011-5-5 21:02:55 | 显示全部楼层
其实我还是想把自己编的改好,毕竟是一次练习,而且还不用dll文件。问能不能帮帮忙……
发表于 2011-5-6 09:47:44 | 显示全部楼层
還是第一次聽說,受教
发表于 2011-5-6 10:17:07 | 显示全部楼层
au3没这种写法。

加密可以直接用官方的
lpxx 发表于 2011-5-2 16:41

你错了,AU3有这种写法.
#include "[路径\]文件名"
#include <文件名>
 楼主| 发表于 2011-5-7 13:45:19 | 显示全部楼层
谁能告诉一下?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-13 14:13 , Processed in 0.076060 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表