-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
80 lines (70 loc) · 4.74 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from ml.trials.trial_10_detect_plaintext_type_with_shift_short_changing_key import \
trial_10_detect_plaintext_type_with_shift_short_changing_key
from ml.trials.trial_11_rnn_detect_plaintext_type_from_shift_cipher_singlekey import \
trial_11_rnn_detect_plaintext_type_from_shift_cipher_singlekey
from ml.trials.trial_1_simple_plaintext_type_sanity_check import trial_1_simple_plaintext_type_sanity_check
from ml.trials.trial_2_detect_plaintext_type_from_shift_cipher_singlekey import \
trial_2_detect_plaintext_type_from_shift_cipher_singlekey
from ml.trials.trial_3_detect_plaintext_type_from_xor_cipher_singlekey import \
trial_3_detect_plaintext_type_from_xor_cipher_singlekey
from ml.trials.trial_4_detect_plaintext_type_from_otp import trial_4_detect_plaintext_type_from_otp
from ml.trials.trial_5_detect_xor_or_shift_cipher_single_keys import trial_5_detect_xor_or_shift_cipher_single_keys
from ml.trials.trial_6_detect_plaintext_type_from_aes_singlekey import trial_6_detect_plaintext_type_from_aes_singlekey
from ml.trials.trial_7_detect_plaintext_type_from_des_singlekey import trial_7_detect_plaintext_type_from_des_singlekey
from ml.trials.trial_8_detect_aes_or_des_cipher_same_key import trial_8_detect_aes_or_des_cipher_same_key
from ml.trials.trial_9_detect_aes_or_des_cipher_changing_keys import trial_9_detect_aes_or_des_cipher_changing_keys
"""
A dictionary of the menu options
"""
MENU_OPTIONS = {
"Trial 1 - Sanity check with plaintext - ML to recognize plaintext type (binary/English text)": trial_1_simple_plaintext_type_sanity_check,
"Trial 2 - Detect plaintext type from cipher text generated by simple SHIFT cipher with same key. ML to recognize plaintext type (binary/English text)": trial_2_detect_plaintext_type_from_shift_cipher_singlekey,
"Trial 3 - Detect plaintext type from cipher text generated by simple XOR cipher with same key. ML to recognize plaintext type (binary/English text)": trial_3_detect_plaintext_type_from_xor_cipher_singlekey,
"Trial 4 - Detect plaintext from OTP - Should fail as impossible": trial_4_detect_plaintext_type_from_otp,
"Trial 5 - Detect from ciphertext which cipher was used between SHIFT or XOR ciphers (with single key) when plaintext is random simple english random plaintext": trial_5_detect_xor_or_shift_cipher_single_keys,
"Trial 6 - Detect plaintext type (Binary/English text) from AES ciphertext using single key": trial_6_detect_plaintext_type_from_aes_singlekey,
"Trial 7 - Detect plaintext type (Binary/English text) from DES ciphertext using single key": trial_7_detect_plaintext_type_from_des_singlekey,
"Trial 8 - Detect from ciphertext which cipher was used between AES or DES ciphers (with single key) when plaintext is random simple english random plaintext": trial_8_detect_aes_or_des_cipher_same_key,
"Trial 9 - Detect from ciphertext which cipher was used between AES or DES ciphers (with random changing keys) when plaintext is random simple english random plaintext": trial_9_detect_aes_or_des_cipher_changing_keys,
"Trial 10 - Detect plaintext type from cipher text generated by simple SHIFT cipher (with random short keys). ML to recognize plaintext type (binary/English text)": trial_10_detect_plaintext_type_with_shift_short_changing_key,
"Trial 11 - Same as #3 only with RNN and variable sizes of inputs": trial_11_rnn_detect_plaintext_type_from_shift_cipher_singlekey,
"Exit": exit
}
def get_user_selection(menu_options):
"""
Gets the use option and validates it
:param menu_options: The number of valid options
:return: The option that was selected or -1 if it is invalid
"""
try:
user_input_str = input("Enter your choice: ")
selection = int(user_input_str)
if selection < 1 or selection > menu_options:
print("Invalid option selected")
return -1
return selection
except ValueError:
print("Error converting str to int")
return -1
def main():
"""
The main runner method for the application
"""
print("******************************************")
print("Machine Learning Cypto-Analyzer by Roy Dar")
print("******************************************")
menu_items_keys = list(MENU_OPTIONS.keys())
menu_items_funcs = list(MENU_OPTIONS.values())
while True:
print()
for index in range(len(menu_items_keys)):
print(str(index + 1) + ") " + menu_items_keys[index])
print()
selection = get_user_selection(len(menu_items_keys))
if not selection == -1:
func = menu_items_funcs[selection - 1]
func()
print()
input("Press Enter to continue...")
if __name__ == '__main__':
main()