MD5
还是请大家帮我改一改这个md5函数,谢谢,我不想用别人的或者用dll文件,谢谢。{:face (327):}#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 你提供的代码不全
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
修改变量后的值。
估计这是最简单的了。时间长了,也许方法不对。 帮忙顶个吧!现在没水平帮上实质性的忙! 就论坛上不是有一些关于MD5的UDF吗???!!?? 可我想编一个不用dll的啊
代码重新发一下#include "huansuan.au3"
#include <Array.au3>
MsgBox(0,"",Md5(""))
Func Md5($string)
Local $1
Local $2
$1 = 19088743
$2 = 19088743
$1 = 2309737967
$2 = 2309737967
$1 = 4275878552
$2 = 4275878552
$1 = 1985229328
$2 = 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
Local $fuzhu1
$fuzhu1 = 7
$fuzhu1 = 12
$fuzhu1 = 17
$fuzhu1 = 22
Local $fuzhu2
$fuzhu2 = 5
$fuzhu2 = 9
$fuzhu2 = 14
$fuzhu2 = 20
Local $fuzhu3
$fuzhu3 = 4
$fuzhu3 = 11
$fuzhu3 = 16
$fuzhu3 = 23
Local $fuzhu4
$fuzhu4 = 6
$fuzhu4 = 10
$fuzhu4 = 15
$fuzhu4 = 21
For $bianliang1 = 0 To $cishu - 1
For $bianliang2 = 1 To 16
$2 = FF($2,$2,$2,$2,$msg[$bianliang][$bianliang2 - 1],$fuzhu1,Int(4294967296 * Abs(Sin($bianliang2))))
Next
For $bianliang2 = 1 To 16
$2 = GG($2,$2,$2,$2,$msg[$bianliang],$fuzhu2,Int(4294967296 * Abs(Sin($bianliang2 + 16))))
Next
$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)
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)
IfMod(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 有人吗?!!!
页:
[1]