Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Created November 29, 2013 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayrx/7704669 to your computer and use it in GitHub Desktop.
Save Ayrx/7704669 to your computer and use it in GitHub Desktop.
Function for constant time string comparison.
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