Created
May 2, 2011 02:03
-
-
Save levigross/951097 to your computer and use it in GitHub Desktop.
Safe hash comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import izip | |
def compare_hash(hashone,hashtwo): | |
if len(hashone) == len(hashtwo): # Every hash should be the same length | |
if sum((ord(o) ^ ord(t) for o,t in izip(hashone,hashtwo))): | |
return False | |
else: | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree, I just wrote this in a verbose manner so people will understand the goal behind the code.