Jump to content
Sign in to follow this  

Doing a XOR on a MD5

Recommended Posts


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:

#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
MsgBox(0, "Error", "Wrong input, try again ...")
Return ""

If StringLeft($h2, 2) = "0x" Then $h2 = StringMid($h2, 3)
If StringIsXDigit($h2) = 0 Then
MsgBox(0, "Error", "Wrong input, try again ...")
Return ""

; 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
ElseIf StringLen($h2) > StringLen($h1) Then
For $i = 1 To StringLen($h2) - StringLen($h1)
$h1 = "0" & $h1

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

Return $result
EndFunc ;==>_BitXOR_Hex

It basically operates a BitXOR on each hex digit at a time.

Gerard J. Pinzonegpinzone AT yahoo.com

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.