aboutsummaryrefslogtreecommitdiff
path: root/slides/2019-side-channels/img/countermeasure.py
blob: dda0868f5a1fe8e904245a96ab198ba8fd958c80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python

def is_equal(s1, s2):
    '''
    Returns true if the strings s1 and s2 encode the same information.
    '''
    if len(s1) != len(s2):
        return False

    result = 0
    for (x,y) in zip(s1,s2):
        result |= ord(x) ^ ord(y)

    return result == 0

target, strs = "abc", [ "ab", "abc", "abcd", "bbc", "abe" ]
for s in strs:
    print("{} == {} ? {}".format(target,s,is_equal(target,s)))