def test_enigma_decipher(self): machine = Enigma(rotors=self.rotors[::-1], reflector=self.reflector) self.assertEqual('AAAAA', machine.cipher('BDZGO'))
def test_generating_key(): enigma = Enigma() key = enigma.generate_key() assert len(list(key)) == 5 assert isinstance(key, str) == True
if args.code: assert not ( ' ' in args.code ), '--code contains a space. Enigma is not compatible with spaces, please correct.' return args if __name__ == "__main__": args = get_args() if args.rotor_demo: demonstrations.rotor_demonstrations() elif args.machine_demo: demonstrations.machine_demonstrations() elif args.codebreaker: codebreaker_tasks.tasks() else: settings = { 'rotors': args.rotors, 'reflector': args.reflector, 'ring_settings': args.ring_settings, 'initial_positions': args.initial_positions, 'plugboard_pairs': args.plugboard_pairs } e = Enigma(settings) e.create_machinery() e.encode(args.code)
plugs = plugboard_wirings break else: print("Directory does not exist, try again.") continue key_in = input("Please enter the key: ") if any(char in not_allowed for char in key_in) or len(key_in) != 18: print("Wrong key format, try again. (Default Settings Set)") else: keys = key_in.upper() encryptor = Enigma(plugs, rotor_settings=list(keys)) """ rotor_who = input("Select a rotor group. (1 - Odd Group | 2- Even Group): ") if rotor_who == '1': encryptor.rotors = Rotors.OddSet elif rotor_who == '2': encryptor.rotors = Rotors.EvenSet else: print("Wrong input, try again.") """ elif op == '2': while True: ask = input("Encrypt or Decrypt? (e/d)")
def test_generate_date(): enigma = Enigma() date = enigma.generate_date() assert isinstance(date, str) == True assert len(list(date)) == 6
-**********************- * * * ENIGMA MACHINE * * * -**********************- AUTHORS: | ID: -------- | ----- MATAN DAVIDIAN | 205509219 TOM DAMRI | 205770068 Tomer Leon | 312203003 Alex Kreinis | 312623218 DATE : 15.11.19 """ e = Enigma() p = Plugboard() p.initials() fast_configure = int( input("FOR FAST CONFIGURE PRESS 0 FOR COSTUME CONFIGURE PRESS 1: ")) if fast_configure == 1: configure = int( input( "Enter 1 to configure plug board, 0 to use the default plug board: " )) if configure: count = 0 match = input( "Enter pairs - less than 10 pairs (for example: AB CD FK): " ).split() for m in match:
] discs_dic = [ dict(alphabet_r), dict(alphabet_r), dict(alphabet_r), dict(alphabet_r), dict(alphabet_r), dict(alphabet_r), ] levels = [] reflector = [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,0] enigma = Enigma(reflector, discs) parser = Parser(argv[1]) def try_level(level): disc = int(level[0]) -1 # disc = discs_dic[disc] backtrack(level, disc, alphabet) def backtrack(level, disc, letters, actual=0): discs_order = [] for l in level: discs_order.append(int(l)-1) discs_order.reverse() to_change = False if len(letters) > 1:
from enigma import Enigma from plugboard import Plugboard from reflector import Reflector from rotor import Rotor e1 = Enigma(rotors=[ Rotor(position=24, type="II"), Rotor(position=13, type="I"), Rotor(position=22, type="III") ], plugboard=Plugboard([ ('A', 'M'), ('F', 'I'), ('N', 'V'), ('P', 'S'), ('T', 'U'), ('W', 'Z'), ]), reflector=Reflector("A") ) e2 = Enigma(rotors=[ Rotor(position=24, type="II"), Rotor(position=13, type="I"), Rotor(position=22, type="III") ], plugboard=Plugboard([ ('A', 'M'), ('F', 'I'), ('N', 'V'), ('P', 'S'),
characteristic2 = input() Rotor(characteristic2).check_len_alphabet() Rotor(characteristic2).repeat_alphabet() print("Provide your third Rotor set.") characteristic3 = input() Rotor(characteristic3).check_len_alphabet() Rotor(characteristic3).repeat_alphabet() print("Provide your Reflector set.") reflect = input() Reflector(reflect).check_len_alphabet() Reflector(reflect).repeat_alphabet() elif a.upper() == "NO": connect = "WNYPVJXTOAMQIZKSRFUHGCEDBL" characteristic1 = "UXBLHWTMCQGZNPYFVOEAJDKSIR" characteristic2 = "TOWYHXUSPAIBRCJEKMFLGDQVZN" characteristic3 = "LCPRTXVZNYEIWGAKMUSQOBDFHJ" reflect = "YRUHQSLDPXNGOKMIEBFZCWVJAT" plugboard = Plugboard(connect) reflektor = Reflector(reflect) enigma = Enigma(plugboard, reflektor, settings) effect = [] for i in user.text: if i == " ": effect.append(i) else: enigma.set_machine(characteristic1, characteristic2, characteristic3) enigma.encode(i) effect = effect + enigma.decode() print("Your encode text is: {}".format("".join(effect)))
def rotor_demonstrations(): # MULTIPLE ROTOR DEMONSTRATION # 1 A -> U settings = { 'rotors': "I II III", 'reflector': 'B', 'ring_settings': '1 1 1', 'initial_positions': 'A A Z', 'plugboard_pairs': None } e = Enigma(settings) e.create_machinery() print("******Demo 1******\n") e.encode('A') print('\n\n') # 2 A -> B settings = { 'rotors': "I II III", 'reflector': 'B', 'ring_settings': '1 1 1', 'initial_positions': 'A A A', 'plugboard_pairs': None } e = Enigma(settings) e.create_machinery() print("******Demo 2******\n") e.encode('A') print('\n\n') # 3 A -> L settings = { 'rotors': "I II III", 'reflector': 'B', 'ring_settings': '1 1 1', 'initial_positions': 'Q E V', 'plugboard_pairs': None } e = Enigma(settings) e.create_machinery() print("******Demo 3******\n") e.encode('A') print('\n\n') # 4 H -> Y settings = { 'rotors': "IV V Beta", 'reflector': 'B', 'ring_settings': '14 9 24', 'initial_positions': 'A A A', 'plugboard_pairs': None } e = Enigma(settings) e.create_machinery() print("******Demo 4******\n") e.encode('H') print('\n\n') # 5 Z -> V settings = { 'rotors': "I II III IV", 'reflector': 'C', 'ring_settings': '7 11 15 19', 'initial_positions': 'Q E V Z', 'plugboard_pairs': None } e = Enigma(settings) e.create_machinery() print("******Demo 5******\n") e.encode('Z') print('\n\n')
def EnigmaClickTest(): enigma = Enigma("CAB", "BAC", "BCA") print(str(enigma)) for i in range(27): enigma.click() print(str(enigma))
from train_utils import * ##### make cipher dataloader ##### data = None if FLAGS.cipher == ciphers[0]: from vigenere import Vigenere data = Vigenere(FLAGS.A, tsteps=FLAGS.tsteps, key_len=FLAGS.key_len) elif FLAGS.cipher == ciphers[1]: from autokey import Autokey data = Autokey(FLAGS.A, tsteps=FLAGS.tsteps, key_len=FLAGS.key_len) elif FLAGS.cipher == ciphers[2]: print( "Note: you must run this in Python 2 because Python 3 does not have the crypto_enigma module yet." ) from enigma import Enigma data = Enigma(FLAGS.A, tsteps=FLAGS.tsteps, key_len=FLAGS.key_len) # only supports keylengths of 3 elif FLAGS.cipher == ciphers[3]: from crack_vigenere import CrackVigenere data = CrackVigenere(FLAGS.A, tsteps=FLAGS.tsteps, key_len=FLAGS.key_len) elif FLAGS.cipher == ciphers[4]: from crack_autokey import CrackAutokey data = CrackAutokey(FLAGS.A, tsteps=FLAGS.tsteps, key_len=FLAGS.key_len) def get_model(FLAGS): global CRACK_MODE model = StackedRNN(FLAGS=FLAGS, crack_mode=CRACK_MODE) model.count_params() return model
# Open file to write messages, clear previus ones with "w" removeAndCreateChatFile(chatFile) waitForTargetFile(targetChatFile) """ Create Enigma for security """ if len(rotorLetters) == 0: print( "You didn't specified rotorletter, default will be used for but it's not recommended" ) rotorLetters = DEFAULT_ROTOR_LETTERS print("rotorLetters", rotorLetters) enigma = Enigma(*rotorLetters) if not first_agent: isFirstAgent = input( "There is a conflict. Are you the first person to send message? y/n: " ) if isFirstAgent.rstrip() == "y": first_agent = True else: first_agent = False if first_agent: # Reset target file if it's not first agent removeAndCreateChatFile(targetChatFile) message = input("Enter first message: ") # Encrypt and send message
import telepot from telepot.delegate import per_from_id, create_open from enigma import Enigma import resposta teste = Enigma ('teste') teste.setMsg ('Oi, como vai?') class SaBOTagem (telepot.helper.UserHandler): def __init__ (self, *args, **kwargs): """Construtor =P""" super (SaBOTagem, self).__init__ (*args, **kwargs) def on_message (self, msg): """Recebeu msg, testa resposta""" print (msg) def open (self, initMsg, seed): """Hora que abrir canal, Enigma 1""" bot.sendMessage (seed, teste.msg) TOKEN = input () bot = telepot.DelegatorBot (TOKEN, [ (per_from_id (), create_open (SaBOTagem, timeout = 3600)), ]) bot.message_loop (run_forever = True)