Exemplo n.º 1
0
 def test_encipher(self):
     'Enigma (test_encipher): encipher operation is identical to decipher operation'
     text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     declist = 'UNLLTTNBWKQEJFSUTGFQVTSGNQLSFEZVLUYDNUDZZKOIFGBYXGUJ'
     key = (('A','B','C'),(6,5,4),'C',('C','B','A'),[('B','V')])
     dec = Enigma(key[0],key[1],key[2],key[3],key[4]).encipher(text)
     self.assertEqual(dec.upper(), declist.upper())
Exemplo n.º 2
0
 def test_encipher(self):
     'Enigma (test_encipher): encipher operation is identical to decipher operation'
     text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     declist = 'UNLLTTNBWKQEJFSUTGFQVTSGNQLSFEZVLUYDNUDZZKOIFGBYXGUJ'
     key = (('A', 'B', 'C'), (6, 5, 4), 'C', ('C', 'B', 'A'), [('B', 'V')])
     dec = Enigma(key[0], key[1], key[2], key[3], key[4]).encipher(text)
     self.assertEqual(dec.upper(), declist.upper())
Exemplo n.º 3
0
 def test_decipher(self):
     'Enigma (test_decipher): try deciphering a few known pairs'
     text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     declist = ['ZVEKPJXYYORZCJPOWSFVDROSCJIUOESGAIPCPOHLJSSWVKWOLEDH',
                'SRBHDZXZESFHYOBCXLBUCOAYUQZPZBWLAYBOEEVJYOEEINLCIHIV',
                'UNLLTTNBWKQEJFSUTGFQVTSGNQLSFEZVLUYDNUDZZKOIFGBYXGUJ',
                'YYQULKSDHEGZECAIUKAZVSIENOQVUCSDZGNCAWUJAYJOTJCPTJOU']
     keys = [(('Q','W','R'),(3,2,4),'C',('R','T','W'),[('E','T'),('N','P')]),
             (('T','B','L'),(1,8,2),'B',('A','B','C'),[('U','P'),('Z','X'),('L','K')]),
             (('A','B','C'),(6,5,4),'C',('C','B','A'),[('B','V')]),
             (('E','W','Q'),(8,7,6),'B',('L','L','L'),[])]                
     for i,key in enumerate(keys):
         dec = Enigma(key[0],key[1],key[2],key[3],key[4]).decipher(text)
         self.assertEqual(dec.upper(), declist[i].upper())  
Exemplo n.º 4
0
 def test_decipher(self):
     'Enigma (test_decipher): try deciphering a few known pairs'
     text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     declist = [
         'ZVEKPJXYYORZCJPOWSFVDROSCJIUOESGAIPCPOHLJSSWVKWOLEDH',
         'SRBHDZXZESFHYOBCXLBUCOAYUQZPZBWLAYBOEEVJYOEEINLCIHIV',
         'UNLLTTNBWKQEJFSUTGFQVTSGNQLSFEZVLUYDNUDZZKOIFGBYXGUJ',
         'YYQULKSDHEGZECAIUKAZVSIENOQVUCSDZGNCAWUJAYJOTJCPTJOU'
     ]
     keys = [
         (('Q', 'W', 'R'), (3, 2, 4), 'C', ('R', 'T', 'W'), [('E', 'T'),
                                                             ('N', 'P')]),
         (('T', 'B', 'L'), (1, 8, 2), 'B', ('A', 'B', 'C'), [('U', 'P'),
                                                             ('Z', 'X'),
                                                             ('L', 'K')]),
         (('A', 'B', 'C'), (6, 5, 4), 'C', ('C', 'B', 'A'), [('B', 'V')]),
         (('E', 'W', 'Q'), (8, 7, 6), 'B', ('L', 'L', 'L'), [])
     ]
     for i, key in enumerate(keys):
         dec = Enigma(key[0], key[1], key[2], key[3], key[4]).decipher(text)
         self.assertEqual(dec.upper(), declist[i].upper())
Exemplo n.º 5
0
def dowork(settings):
    for setting in settings:
        enc_key = Enigma(setting[0], setting[1], setting[2], setting[3],
                         setting[4])
        dec_key = enc_key.encipher('UKJ')
        enc = Enigma(dec_key, setting[1], setting[2], setting[3], setting[4])
        pt = enc.decipher(cipher)
        if string in pt:
            fh = open('pt.txt', 'w')
            fh.write(
                "\nSettings:\n\tKey: %s\n\tRotors: %s" % dec_key,
                setting[1] + "\n\tReflector: %s\n\tRings: %s" % setting[2],
                setting[3] + "\n\tSteckers: %s\n\tMessage: %s\n" % setting[4],
                pt)
            fh.close()
            break
    return pt