Created
November 29, 2013 11:53
-
-
Save Ayrx/7704669 to your computer and use it in GitHub Desktop.
Function for constant time string 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
def is_equal(a, b): | |
if len(a) != len(b): | |
return False | |
result = 0 | |
for x, y in zip(a, b): | |
result |= x ^ y | |
return result == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment