def strings_differ(string1, string2, compare_digest=compare_digest):
 len_eq = (len(string1) == len(string2))
 if len_eq:
  invalid_bits = 0
  left = string1
 else:
  invalid_bits = 1
  left = string2
 right = string2
 if (compare_digest is not None):
  invalid_bits += (not compare_digest(left, right))
 else:
  for (a, b) in zip(left, right):
   invalid_bits += (a != b)
 return (invalid_bits != 0)

def strings_differ ( string1 , string2 , compare_digest = compare_digest ) : len_eq = ( len ( string1 ) == len ( string2 ) ) if len_eq : invalid_bits = 0 left = string1 else : invalid_bits = 1 left = string2 right = string2 if ( compare_digest is not None ) : invalid_bits += ( not compare_digest ( left , right ) ) else : for ( a , b ) in zip ( left , right ) : invalid_bits += ( a != b ) return ( invalid_bits != 0 )
check whether two strings differ while avoiding timing attacks .