Last active
April 15, 2022 17:21
-
-
Save abgeana/45e5e46c616886a78893a5f8b17b77a1 to your computer and use it in GitHub Desktop.
AES DFA
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
bool check_faults(uint8_t *ct, uint8_t *expected_ct) { | |
bool good_fault; | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 1 || i == 8 || i == 11 || i == 14) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 2 || i == 5 || i == 12 || i == 15) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 3 || i == 6 || i == 9 || i == 16) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 4 || i == 7 || i == 10 || i == 13) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 1 || i == 6 || i == 11 || i == 16) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 2 || i == 7 || i == 12 || i == 13) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 3 || i == 8 || i == 9 || i == 14) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
good_fault = true; | |
for (int i = 1; i <= 16; i++) { | |
if (i == 4 || i == 5 || i == 10 || i == 15) { | |
if (ct[i] == expected_ct[i]) { | |
good_fault = false; | |
} | |
} else { | |
if (ct[i] != expected_ct[i]) { | |
good_fault = false; | |
} | |
} | |
} | |
if (good_fault) { | |
return true; | |
} | |
return false; | |
} |
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
#! env python | |
import sys | |
def check_faults(ct, expected_ct): | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [1, 8, 11, 14]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [2, 5, 12, 15]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [3, 6, 9, 16]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [4, 7, 10, 13]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [1, 6, 11, 16]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [2, 7, 12, 13]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [3, 8, 9, 14]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
good_fault = True | |
for i in range(0, 16): | |
if i + 1 in [4, 5, 10, 15]: | |
if ct[i] == expected_ct[i]: | |
good_fault = False | |
else: | |
if ct[i] != expected_ct[i]: | |
good_fault = False | |
if good_fault: | |
return True | |
return False | |
def diff(ct, expected_ct): | |
d = str() | |
for i in range(16): | |
if i != 0 and i % 4 == 0: | |
d += ' ' | |
if ct[i] == expected_ct[i]: | |
d += '*' | |
else: | |
d += '.' | |
return d | |
def main(): | |
expected_ct = bytes.fromhex(sys.argv[1]) | |
line = sys.stdin.readline() | |
while line is not None: | |
line = line.strip('\n') | |
if line == '': | |
break | |
ct = bytes.fromhex(line) | |
if check_faults(ct, expected_ct): | |
print('[y] ', end='') | |
else: | |
print('[n] ', end='') | |
print(expected_ct.hex(), line, diff(ct, expected_ct)) | |
sys.stdout.flush() | |
line = sys.stdin.readline() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment