Created
December 24, 2012 22:10
-
-
Save lucassmagal/4370831 to your computer and use it in GitHub Desktop.
constant-time algorithm for string comparing in Python. This is a refactoring of a snippet found in http://codahale.com/a-lesson-in-timing-attacks/ to work with strings.
This file contains hidden or 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
def is_equal(a, b): | |
result = 0 | |
for x, y in zip(a, b): | |
result |= ord(x) ^ ord(y) | |
return result == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment