def trial_4_detect_plaintext_type_from_otp(): """ Trial 4 ------- Testing ability to recognize the type of text when the cipher is a real OTP (random key for each specimen) The task of the ML is to recognize the difference between english text and binary data Proven to be impossible when the keys are single use and true random, so we expect this to fail ML model - FC NN Training rounds = 50 Plaintext = Binary / Text Ciphers = OTP (XOR with random key for each record) Result = Failure """ evaluation_field = EncryptionDatastoreConstants.PLAINTEXT_TYPE possible_values = EncryptionDatastoreConstants.POSSIBLE_PLAINTEXT_TYPES plaintext_generators = None # use default encryption_generators = { (EncryptionMethod.XOR, BlockMode.ECB): EncryptionManager( EncryptionMethod.XOR, encryption_key_size=2000) } model_creator = KerasFullyConnectedNNModelCreator(len(possible_values)) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators)
def trial_3_detect_plaintext_type_from_xor_cipher_singlekey(): """ Trial 3 ------- Testing ability to recognize the type of text when the cipher is a simple XOR with a single key The task of the ML is to recognize the difference between english text and binary data ML model - FC NN Training rounds = 50 Plaintext = Binary / Text Ciphers = XOR (single key) Result = Success """ evaluation_field = EncryptionDatastoreConstants.PLAINTEXT_TYPE possible_values = EncryptionDatastoreConstants.POSSIBLE_PLAINTEXT_TYPES plaintext_generators = None # use default encryption_generators = { (EncryptionMethod.XOR, BlockMode.ECB): EncryptionManager(EncryptionMethod.XOR, encryption_key=get_random_bytes(2000)) } model_creator = KerasFullyConnectedNNModelCreator(len(possible_values)) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators)
def trial_10_detect_plaintext_type_with_shift_short_changing_key(): """ Trial 10 ------- Testing ability to recognize the type of text when the cipher shift with short key length The task of the ML is to recognize the difference between english text and binary data ML model - FC NN Training rounds = 1000 Plaintext = Binary / Text Ciphers = SHIFT (changing keys of short size) Result = Success """ evaluation_field = EncryptionDatastoreConstants.PLAINTEXT_TYPE possible_values = EncryptionDatastoreConstants.POSSIBLE_PLAINTEXT_TYPES plaintext_generators = None # use default encryption_generators = { (EncryptionMethod.SHIFT, BlockMode.ECB): EncryptionManager(EncryptionMethod.SHIFT, encryption_key_size=5) } model_creator = KerasFullyConnectedNNModelCreator(len(possible_values), hidden_layers=5) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators, training_rounds=100)
def trial_1_simple_plaintext_type_sanity_check(): """ Trial 1 ------- This is just a small sanity check Since there is no cipher the cipertext=plaintext The task of the ML is to recognize the difference between english text and binary data directly from the data A very easy task ML model - FC NN Training rounds = 50 Plaintext = Binary / Text Ciphers = None Result = Success """ evaluation_field = EncryptionDatastoreConstants.PLAINTEXT_TYPE possible_values = EncryptionDatastoreConstants.POSSIBLE_PLAINTEXT_TYPES plaintext_generators = None # use default encryption_generators = {("NONE", None): None} model_creator = KerasFullyConnectedNNModelCreator(len(possible_values)) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators, training_rounds=50)
def trial_6_detect_plaintext_type_from_aes_singlekey(): """ Trial 6 ------- Testing ability to recognize the type of plaintext when the cipher is a AES with a single key The task of the ML is to recognize the difference between english text and binary data ML model - FC NN, 5 hidden layers of 100 hidden units per layer Training rounds = 1000 Plaintext = Binary / Text Ciphers = AES (single key) Result = Failure """ evaluation_field = EncryptionDatastoreConstants.PLAINTEXT_TYPE possible_values = EncryptionDatastoreConstants.POSSIBLE_PLAINTEXT_TYPES plaintext_generators = None # use default encryption_generators = { (EncryptionMethod.AES, BlockMode.ECB): EncryptionManager(EncryptionMethod.AES, encryption_key=get_random_bytes(32)) } model_creator = KerasFullyConnectedNNModelCreator(len(possible_values), hidden_layers=5, units_per_layer=100) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators, training_rounds=1000)
def trial_8_detect_aes_or_des_cipher_same_key(): """ Trial 8 ------- Testing ability to recognize the type of cipher used from AES or DES ciphers when the plaintext is english text only The task of the ML is to recognize the cipher that was used Each cipher will use different keys for every encryption operation ML model - FC NN, 5 hidden layers of 100 hidden units per layer Training rounds = 1000 Plaintext = Text Ciphers = DES (with same key) / AES (with same key) Result = Partial Success """ evaluation_field = EncryptionDatastoreConstants.ENCRYPTION_METHOD possible_values = EncryptionDatastoreConstants.POSSIBLE_ENCRYPTION_METHODS plaintext_generators = { EncryptionDatastoreConstants.PLAINTEXT_TYPE_DICT: DictionaryPlaintextGenerator(ENGLISH_DICT_PATH, 1000, 1500) } encryption_generators = { (EncryptionMethod.DES, BlockMode.ECB): EncryptionManager(EncryptionMethod.DES, encryption_key=get_random_bytes(8)), (EncryptionMethod.AES, BlockMode.ECB): EncryptionManager(EncryptionMethod.AES, encryption_key=get_random_bytes(32)) } model_creator = KerasFullyConnectedNNModelCreator( len(possible_values), units_per_layer=100, hidden_layers=5, embedded_binary_data=True) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators, training_rounds=1000, inputs_per_round=1000)
def trial_5_detect_xor_or_shift_cipher_single_keys(): """ Trial 5 ------- Testing ability to recognize the type of cipher used from XOR or SHIFT ciphers when the plaintext is english text only The task of the ML is to recognize the cipher that was used Each cipher will use the same key all the time ML model - FC NN, 5 hidden layers of 100 hidden units per layer Training rounds = 50 Plaintext = Text Ciphers = XOR (with single key) / SHIFT (with single key) Result = Success """ evaluation_field = EncryptionDatastoreConstants.ENCRYPTION_METHOD possible_values = EncryptionDatastoreConstants.POSSIBLE_ENCRYPTION_METHODS plaintext_generators = { EncryptionDatastoreConstants.PLAINTEXT_TYPE_DICT: DictionaryPlaintextGenerator(ENGLISH_DICT_PATH, 1000, 1500) } encryption_generators = { (EncryptionMethod.XOR, BlockMode.ECB): EncryptionManager(EncryptionMethod.XOR, encryption_key=get_random_bytes(2000)), (EncryptionMethod.SHIFT, BlockMode.ECB): EncryptionManager(EncryptionMethod.SHIFT, encryption_key=get_random_bytes(2000)) } model_creator = KerasFullyConnectedNNModelCreator(len(possible_values), units_per_layer=100, hidden_layers=5) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators, training_rounds=50)
def trial_9_detect_aes_or_des_cipher_changing_keys(): """ Trial 9 ------- Testing ability to recognize the type of cipher used from AES or DES ciphers when the plaintext is english text only The task of the ML is to recognize the cipher that was used Each cipher will use different keys for every encryption operation Expected to fail ML model - FC NN, 5 hidden layers of 100 hidden units per layer Training rounds = 1000 Plaintext = Text Ciphers = DES (with changing keys) / AES (with changing keys) Result = Failure """ evaluation_field = EncryptionDatastoreConstants.ENCRYPTION_METHOD possible_values = EncryptionDatastoreConstants.POSSIBLE_ENCRYPTION_METHODS plaintext_generators = { EncryptionDatastoreConstants.PLAINTEXT_TYPE_DICT: DictionaryPlaintextGenerator(ENGLISH_DICT_PATH, 1000, 1500) } encryption_generators = { (EncryptionMethod.DES, BlockMode.ECB): EncryptionManager(EncryptionMethod.DES, encryption_key_size=8), (EncryptionMethod.AES, BlockMode.ECB): EncryptionManager(EncryptionMethod.AES, encryption_key_size=32) } model_creator = KerasFullyConnectedNNModelCreator(len(possible_values), units_per_layer=100, hidden_layers=5) train_and_evaluate(model_creator, evaluation_field, possible_values, plaintext_generators, encryption_generators, training_rounds=1000)