xlbcwn 发表于 2011-5-2 11:23:13

Md5函数

本帖最后由 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]
        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],7,3614090360)
                $d = FF($d,$a,$b,$c,$msg[$bianliang],12,3905402710)
                $c = FF($c,$d,$a,$b,$msg[$bianliang],17,606105819)
                $b = FF($b,$c,$d,$a,$msg[$bianliang],22,3250441966)
                $a = FF($a,$b,$c,$d,$msg[$bianliang],7,4118548399)
                $d = FF($d,$a,$b,$c,$msg[$bianliang],12,1200080426)
                $c = FF($c,$d,$a,$b,$msg[$bianliang],17,2821735955)
                $b = FF($b,$c,$d,$a,$msg[$bianliang],22,4249261313)
                $a = FF($a,$b,$c,$d,$msg[$bianliang],7,1770035416)
                $d = FF($d,$a,$b,$c,$msg[$bianliang],12,2336552879)
                $c = FF($c,$d,$a,$b,$msg[$bianliang],17,4294925233)
                $b = FF($b,$c,$d,$a,$msg[$bianliang],22,2304563134)
                $a = FF($a,$b,$c,$d,$msg[$bianliang],7,1804603682)
                $d = FF($d,$a,$b,$c,$msg[$bianliang],12,4254626195)
                $c = FF($c,$d,$a,$b,$msg[$bianliang],17,2792965006)
                $b = FF($b,$c,$d,$a,$msg[$bianliang],22,1236535329)

                $a = GG($a,$b,$c,$d,$msg[$bianliang],5,4129170786)
                $d = GG($d,$a,$b,$c,$msg[$bianliang],9,3225465664)
                $c = GG($c,$d,$a,$b,$msg[$bianliang],14,643717713)
                $b = GG($b,$c,$d,$a,$msg[$bianliang],20,3921069994)
                $a = GG($a,$b,$c,$d,$msg[$bianliang],5,3593408605)
                $d = GG($d,$a,$b,$c,$msg[$bianliang],9,38016083)
                $c = GG($c,$d,$a,$b,$msg[$bianliang],14,3634488961)
                $b = GG($b,$c,$d,$a,$msg[$bianliang],20,3889429448)
                $a = GG($a,$b,$c,$d,$msg[$bianliang],5,568446438)
                $d = GG($d,$a,$b,$c,$msg[$bianliang],9,3275163606)
                $c = GG($c,$d,$a,$b,$msg[$bianliang],14,4107603335)
                $b = GG($b,$c,$d,$a,$msg[$bianliang],20,1163531501)
                $a = GG($a,$b,$c,$d,$msg[$bianliang],5,2850285829)
                $d = GG($d,$a,$b,$c,$msg[$bianliang],9,4243563512)
                $c = GG($c,$d,$a,$b,$msg[$bianliang],14,1735328473)
                $b = GG($b,$c,$d,$a,$msg[$bianliang],20,2368359562)

                $a = HH($a,$b,$c,$d,$msg[$bianliang],4,4294588738)
                $d = HH($d,$a,$b,$c,$msg[$bianliang],11,2272392833)
                $c = HH($c,$d,$a,$b,$msg[$bianliang],16,1839030562)
                $b = HH($b,$c,$d,$a,$msg[$bianliang],23,4259657740)
                $a = HH($a,$b,$c,$d,$msg[$bianliang],4,2763975236)
                $d = HH($d,$a,$b,$c,$msg[$bianliang],11,1272893353)
                $c = HH($c,$d,$a,$b,$msg[$bianliang],16,4139469664)
                $b = HH($b,$c,$d,$a,$msg[$bianliang],23,3200236656)
                $a = HH($a,$b,$c,$d,$msg[$bianliang],4,681279174)
                $d = HH($d,$a,$b,$c,$msg[$bianliang],11,3936430074)
                $c = HH($c,$d,$a,$b,$msg[$bianliang],16,3572445317)
                $b = HH($b,$c,$d,$a,$msg[$bianliang],23,76029189)
                $a = HH($a,$b,$c,$d,$msg[$bianliang],4,3654602809)
                $d = HH($d,$a,$b,$c,$msg[$bianliang],11,3873151461)
                $c = HH($c,$d,$a,$b,$msg[$bianliang],16,530742520)
                $b = HH($b,$c,$d,$a,$msg[$bianliang],23,3299628645)

                $a = II($a,$b,$c,$d,$msg[$bianliang],6,4096336452)
                $d = II($d,$a,$b,$c,$msg[$bianliang],10,1126891415)
                $c = II($c,$d,$a,$b,$msg[$bianliang],15,2878612391)
                $b = II($b,$c,$d,$a,$msg[$bianliang],21,4237533241)
                $a = II($a,$b,$c,$d,$msg[$bianliang],6,1700485571)
                $d = II($d,$a,$b,$c,$msg[$bianliang],10,2399980690)
                $c = II($c,$d,$a,$b,$msg[$bianliang],15,4293915773)
                $b = II($b,$c,$d,$a,$msg[$bianliang],21,2240044497)
                $a = II($a,$b,$c,$d,$msg[$bianliang],6,1873313359)
                $d = II($d,$a,$b,$c,$msg[$bianliang],10,4264355552)
                $c = II($c,$d,$a,$b,$msg[$bianliang],15,2734768916)
                $b = II($b,$c,$d,$a,$msg[$bianliang],21,1309151649)
                $a = II($a,$b,$c,$d,$msg[$bianliang],6,4149444226)
                $d = II($d,$a,$b,$c,$msg[$bianliang],10,3174756917)
                $c = II($c,$d,$a,$b,$msg[$bianliang],15,718787259)
                $b = II($b,$c,$d,$a,$msg[$bianliang],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

lpxx 发表于 2011-5-2 16:41:19

本帖最后由 lpxx 于 2011-5-2 16:42 编辑

#include "huansuan.au3"au3没这种写法。

加密可以直接用官方的#include <ACN_HASH.au3>
MsgBox(0, "", _MD5("a"))

xlbcwn 发表于 2011-5-2 17:04:17

有这个函数?

xlbcwn 发表于 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

xlbcwn 发表于 2011-5-5 21:02:55

其实我还是想把自己编的改好,毕竟是一次练习,而且还不用dll文件。问能不能帮帮忙……

zzz867 发表于 2011-5-6 09:47:44

還是第一次聽說,受教

3mile 发表于 2011-5-6 10:17:07

au3没这种写法。

加密可以直接用官方的
lpxx 发表于 2011-5-2 16:41 http://www.autoitx.com/images/common/back.gif
你错了,AU3有这种写法.
#include "[路径\]文件名"
#include <文件名>

xlbcwn 发表于 2011-5-7 13:45:19

谁能告诉一下?
页: [1]
查看完整版本: Md5函数