Beispiel #1
0
class MarkIV(MarkI):
    def __init__(self, setting_1, setting_2):
        self.wheels = MarkII(setting_1, setting_2)
        self.setting = 0

    def encodeLetter(self, letter):
        partial = self.wheels.encode(letter)
        result = super(MarkIV, self).encodeLetter(partial)
        self.setting = self.cipher.index(letter) * 2
        return result

    def decodeLetter(self, letter):
        partial = super(MarkIV, self).decodeLetter(letter)
        result = self.wheels.decode(partial)
        self.setting = self.cipher.index(result) * 2
        return result
Beispiel #2
0
class TestMarkIV(unittest.TestCase):
    def setUp(self):
        self.mark2 = MarkII(4, 7)
        self.mark4 = MarkIV(4, 7)

    def testInitialEncode(self):
        self.assertEquals(self.mark4.encode('H'), 
                          self.mark2.encode('H'),
                          "Initial encoding of MarkIV should be the same as the MarkII")

    def testSecondEncode(self):
        self.assertNotEquals(self.mark4.encode('HE'), 
                             self.mark2.encode('HE'),
                             "Second encoding of MarkIV should be different from the MarkII")

    def testQuestionThree(self):
        self.assertEquals(self.mark4.encode('The white cliffs of Alghero are visible at night'),
                          'JMl0kBp?20QixoivSc.2"vvmls8KOk"0jA,4kgt0OmUb,pm.')

    def testDecodeString(self):
        self.assertEquals(self.mark4.decode('JMl0kBp?20QixoivSc.2"vvmls8KOk"0jA,4kgt0OmUb,pm.'), 
                                            'The white cliffs of Alghero are visible at night')
Beispiel #3
0
class TestMarkII(unittest.TestCase):
    def setUp(self):
        self.mark2 = MarkII(2, 5)

    def testExample(self):
        self.assertEquals(self.mark2.encode('a'), 'S')
        self.assertEquals(self.mark2.encode('b'), 'T')
        self.assertEquals(self.mark2.encode('c'), 'U')
        self.assertEquals(self.mark2.encode('abc'), 'STU')

    def testQuestionTwo(self):
        mark2 = MarkII(9, 3)
        self.assertEquals(mark2.encode('The Desert Fox will move 30 tanks to Calais at dawn'),
                          'Wkh2Ghvhuw2Ir.2zloo2pryh2632wdqnv2wr2Fdodlv2dw2gdzq')

    def testDecodeLetter(self):
        self.assertEquals(self.mark2.decode('S'), 'a')
        self.assertEquals(self.mark2.decode('T'), 'b')
        self.assertEquals(self.mark2.decode('U'), 'c')
        self.assertEquals(self.mark2.decode('STU'), 'abc')
Beispiel #4
0
 def setUp(self):
     self.mark2 = MarkII(4, 7)
     self.mark4 = MarkIV(4, 7)
Beispiel #5
0
 def testQuestionTwo(self):
     mark2 = MarkII(9, 3)
     self.assertEquals(mark2.encode('The Desert Fox will move 30 tanks to Calais at dawn'),
                       'Wkh2Ghvhuw2Ir.2zloo2pryh2632wdqnv2wr2Fdodlv2dw2gdzq')
Beispiel #6
0
 def setUp(self):
     self.mark2 = MarkII(2, 5)
Beispiel #7
0
 def __init__(self, setting_1, setting_2):
     self.wheels = MarkII(setting_1, setting_2)
     self.setting = 0