找回密码
 加入
搜索
查看: 3223|回复: 5

[AU3基础] MD5

  [复制链接]
发表于 2011-7-10 10:19:01 | 显示全部楼层 |阅读模式
还是请大家帮我改一改这个md5函数,谢谢,我不想用别人的或者用dll文件,谢谢。
#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-7-10 17:33:50 | 显示全部楼层
你提供的代码不全
MD5只是中间结果,所以最简单的方法有:
1.修改117行
Return from10($a1,16) & from10($b1,16) & from10($c1,16) & from10($d1,16)

变换次序
2.修改第8,9行
Local $a1 = 19088743,$b1 = 2309737967,$c1 = 4275878552,$d1 = 1985229328
Local $a = 19088743,$b = 2309737967,$c = 4275878552,$d = 1985229328

修改变量后的值。

估计这是最简单的了。时间长了,也许方法不对。
发表于 2011-7-11 01:05:18 | 显示全部楼层
帮忙顶个吧!现在没水平帮上实质性的忙!
发表于 2011-7-11 18:57:12 | 显示全部楼层
就论坛上不是有一些关于MD5的UDF吗???!!??
 楼主| 发表于 2011-7-19 09:55:45 | 显示全部楼层
可我想编一个不用dll的啊
代码重新发一下
#include "huansuan.au3"
#include <Array.au3>

MsgBox(0,"",Md5(""))

Func Md5($string)
        Local $1[5]
        Local $2[5]
        $1[1] = 19088743
        $2[1] = 19088743
        $1[2] = 2309737967
        $2[2] = 2309737967
        $1[3] = 4275878552
        $2[3] = 4275878552
        $1[4] = 1985229328
        $2[4] = 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

        Local $fuzhu1[5]
        $fuzhu1[1] = 7
        $fuzhu1[2] = 12
        $fuzhu1[3] = 17
        $fuzhu1[4] = 22

        Local $fuzhu2[5]
        $fuzhu2[1] = 5
        $fuzhu2[2] = 9
        $fuzhu2[3] = 14
        $fuzhu2[4] = 20

        Local $fuzhu3[5]
        $fuzhu3[1] = 4
        $fuzhu3[2] = 11
        $fuzhu3[3] = 16
        $fuzhu3[4] = 23

        Local $fuzhu4[5]
        $fuzhu4[1] = 6
        $fuzhu4[2] = 10
        $fuzhu4[3] = 15
        $fuzhu4[4] = 21

        For $bianliang1 = 0 To $cishu - 1
                For $bianliang2 = 1 To 16
                        $2[Mod($bianliang2 - 1,4) + 1] = FF($2[Mod($bianliang2 - 1,4) + 1],$2[Mod($bianliang2,4) + 1],$2[Mod($bianliang2 + 1,4) + 1],$2[Mod($bianliang2 + 2,4) + 1],$msg[$bianliang][$bianliang2 - 1],$fuzhu1[Mod($bianliang2 - 1,4) + 1],Int(4294967296 * Abs(Sin($bianliang2))))
                Next

                For $bianliang2 = 1 To 16
                        $2[Mod(17 - $bianliang2,4) + 1] = GG($2[Mod(17 - $bianliang2,4) + 1],$2[Mod(18 - $bianliang2,4) + 1],$2[Mod(19 - $bianliang2,4) + 1],$2[Mod(20 - $bianliang2,4) + 1],$msg[$bianliang][Mod(5 * ($bianliang2 - 1) + 1,16)],$fuzhu2[Mod($bianliang2 - 1,4) + 1],Int(4294967296 * Abs(Sin($bianliang2 + 16))))
                Next

                $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)

                For $bianliang2 = 1 To 4
                        $1[$bianliang2] += $2[$bianliang2]
                Next
        Next
        ;Return from10($a1 + $b1 + $c1 + $d1,16)
        ;Return $a1 & " " & $b1 & " " & $c1 & " " & $d1
        MsgBox(0,"",$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)
        Local $linshi = from10($m,16)
        $linshi = to10(StringTrimLeft($linshi,$n) & StringLeft($linshi,$n),16)
        Return $linshi
        ;Return BitRotate($m,$n,"D")
        ;Return BitShift($m,-$n)
EndFunc
还有转换的
#include-once
Func zhizhen($value)
        Return to10(zhizhenxingshi(from10($value,16)),16)
EndFunc

Func zhizhenxingshi($string)
        If  Mod(StringLen($string),2) Then $string = "0" & $string
        Local $shuchu = ""
        While StringLen($string)
                $shuchu &= StringRight($string,2)
                $string = StringTrimRight($string,2)
        WEnd
        Return $shuchu
EndFunc

Func xput($value,Const $yuanjinlv = 10,Const $xianjinlv = 10)
        $value = StringUpper($value)
        If shucunzai($value,$yuanjinlv) Then Return from10(to10($value,$yuanjinlv),$xianjinlv)
EndFunc

Func shucunzai($value,$jinlv)
        $value = StringUpper($value)
        Do
                $2 = Asc($value) - 48
                $value = StringTrimLeft($value,1)
                If $2 > 9 Then $2 -= 7
                If $2 >= $jinlv Then
                        Return 0
                EndIf
        Until "" = $value
        Return 1
EndFunc

Func from10($value,Const $radix = 10)
        Local $shuchu = ""
        Do
                $2 = Mod($value,$radix)+48
                If $2 > 57 Then $2 += 7
                $value = Int ($value / $radix)
                $shuchu = Chr($2) & $shuchu
        Until 0 = $value
        Return $shuchu
EndFunc

Func to10($value,Const $jinlv = 10)
        $value = StringUpper($value)
        Local $shuchu = 0
        Do
                $shuchu = $jinlv * $shuchu
                $2 = Asc($value)-48
                $value = StringTrimLeft($value,1)
                If $2 > 9 Then $2 -= 7
                $shuchu += $2
        Until "" = $value
        Return $shuchu
EndFunc
 楼主| 发表于 2011-8-5 13:02:31 | 显示全部楼层
有人吗?!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

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

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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