GPinzone Posted December 6, 2012 Share Posted December 6, 2012 I needed to perform an XOR on two MD5 hashes. The problem is that a MD5 will overflow an integer, so AutoIT treats it as a string. I came up with a function to handle this, but I'm sure that it's not as efficient as it could be. Here's what I came up with: expandcollapse popup#include <Crypt.au3> Func md5($message) Return _Crypt_HashData($message, $CALG_MD5) EndFunc ;==>md5 Func _BitXOR_Hex($h1, $h2) If StringLeft($h1, 2) = "0x" Then $h1 = StringMid($h1, 3) If StringIsXDigit($h1) = 0 Then SetError(1) MsgBox(0, "Error", "Wrong input, try again ...") Return "" EndIf If StringLeft($h2, 2) = "0x" Then $h2 = StringMid($h2, 3) If StringIsXDigit($h2) = 0 Then SetError(1) MsgBox(0, "Error", "Wrong input, try again ...") Return "" EndIf ; Add leading zeros to smaller hex string if different length. If StringLen($h1) > StringLen($h2) Then For $i = 1 To StringLen($h1) - StringLen($h2) $h2 = "0" & $h2 Next ElseIf StringLen($h2) > StringLen($h1) Then For $i = 1 To StringLen($h2) - StringLen($h1) $h1 = "0" & $h1 Next EndIf Local $result = "0x" For $i = 1 To StringLen($h1) Local $t1 = "0x" & StringMid($h1, $i, 1) Local $t2 = "0x" & StringMid($h2, $i, 1) Local $t3 = StringMid($HX_REF, BitXOR($t1, $t2) + 1, 1) $result = $result & $t3 Next Return $result EndFunc ;==>_BitXOR_Hex It basically operates a BitXOR on each hex digit at a time. Gerard J. Pinzonegpinzone AT yahoo.com Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now