Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Doing a XOR on a MD5

$
0
0
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:

[ autoit ]         
#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.

Viewing all articles
Browse latest Browse all 12506

Trending Articles