#NEWLINE# def constant_time_compare( val1 , val2 ) : #NEWLINE# #INDENT# '\n    Returns True if the two strings are equal, False otherwise.\n\n    The time taken is independent of the number of characters that match.\n    ' #NEWLINE# if ( len ( val1 ) != len ( val2 ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# result = 0 #NEWLINE# for ( x , y ) in zip ( val1 , val2 ) : #NEWLINE# #INDENT# result |= ( ord ( x ) ^ ord ( y ) ) #NEWLINE# #UNINDENT# return ( result == 0 )