Ejemplo n.º 1
0
 def test_can_encode(self):
     cipher = Cipher()
     plaintext = 'aaaaaaaaaa'
     self.assertEqual(cipher.encode(plaintext), cipher.key[:len(plaintext)])
Ejemplo n.º 2
0
 def test_throws_an_error_with_all_uppercase_key(self):
     with self.assertRaisesWithMessage(ValueError):
         Cipher('ABCDEF')
Ejemplo n.º 3
0
 def test_throws_an_error_with_empty_key(self):
     with self.assertRaisesWithMessage(ValueError):
         Cipher('')
Ejemplo n.º 4
0
 def test_encode_always_returns_downcase_string(self):
     cipher = Cipher()
     plaintext = 'AbCdEfGhIj'
     ciphertext = 'bcdefghijk'
     self.assertEqual(ciphertext, cipher.encode(plaintext))
Ejemplo n.º 5
0
 def test_can_wrap_on_decode(self):
     cipher = Cipher('abcdefghij')
     self.assertEqual(cipher.decode('zabcdefghi'), 'zzzzzzzzzz')
Ejemplo n.º 6
0
 def test_can_wrap_on_decode(self):
     cipher = Cipher('abcdefghij')
     self.assertEqual(cipher.decode('zabcdefghi'), 'zzzzzzzzzz')
Ejemplo n.º 7
0
 def test_cipher_encode4(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     c = Cipher(key)
     self.assertEqual('gccwkixcltycv', c.encode('diffiehellman'))
 def test_can_wrap_on_decode(self):
     cipher = Cipher("abcdefghij")
     self.assertEqual(cipher.decode("zabcdefghi"), "zzzzzzzzzz")
 def test_can_encode_messages_longer_than_the_key(self):
     cipher = Cipher("abc")
     plaintext = "iamapandabear"
     self.assertEqual(cipher.encode(plaintext), "iboaqcnecbfcr")
 def test_can_double_shift_encode(self):
     cipher = Cipher("iamapandabear")
     plaintext = "iamapandabear"
     self.assertEqual(cipher.encode(plaintext), "qayaeaagaciai")
 def test_can_wrap_on_encode(self):
     cipher = Cipher("abcdefghij")
     plaintext = "zzzzzzzzzz"
     self.assertEqual(cipher.encode(plaintext), "zabcdefghi")
 def test_can_decode(self):
     cipher = Cipher("abcdefghij")
     self.assertEqual(cipher.decode(cipher.key), "aaaaaaaaaa")
 def test_can_encode(self):
     cipher = Cipher("abcdefghij")
     plaintext = "aaaaaaaaaa"
     self.assertEqual(cipher.encode(plaintext), cipher.key)
 def test_can_encode(self):
     cipher = Cipher()
     plaintext = "aaaaaaaaaa"
     self.assertEqual(cipher.encode(plaintext), cipher.key[0: len(plaintext)])
Ejemplo n.º 15
0
 def test_can_encode(self):
     cipher = Cipher('abcdefghij')
     self.assertEqual(cipher.encode('aaaaaaaaaa'), cipher.key)
 def test_can_decode_messages_longer_than_the_key(self):
     cipher = Cipher("abc")
     self.assertEqual(cipher.decode("iboaqcnecbfcr"), "iamapandabear")
Ejemplo n.º 17
0
 def test_is_reversible(self):
     cipher = Cipher('abcdefghij')
     plaintext = 'abcdefghij'
     self.assertEqual(cipher.decode(cipher.encode(plaintext)), plaintext)
 def test_cipher_encode2(self):
     c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
     self.assertEqual(
         c.encode('itisawesomeprogramminginpython'),
         'itisawesomeprogramminginpython')
Ejemplo n.º 19
0
 def test_cipher_encode2(self):
     c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
     self.assertEqual('itisawesomeprogramminginpython',
                      c.encode('itisawesomeprogramminginpython'))
 def test_cipher_encode3(self):
     c = Cipher('dddddddddddddddddddddd')
     self.assertEqual(c.encode('venividivici'), 'yhqlylglylfl')
Ejemplo n.º 21
0
 def test_cipher_compositiion1(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher(key)
     self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
 def test_cipher_encode4(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     c = Cipher(key)
     self.assertEqual(c.encode('diffiehellman'), 'gccwkixcltycv')
Ejemplo n.º 23
0
 def test_can_double_shift_encode(self):
     plaintext = 'iamapandabear'
     cipher = Cipher(plaintext)
     self.assertEqual(cipher.encode(plaintext), 'qayaeaagaciai')
 def test_cipher_encode_short_key(self):
     c = Cipher('abcd')
     self.assertEqual(c.encode('aaaaaaaa'), 'abcdabcd')
Ejemplo n.º 25
0
 def test_can_handle_messages_longer_than_key(self):
     cipher = Cipher('abc')
     self.assertEqual(cipher.encode('iamapandabear'), 'iboaqcnecbfcr')
 def test_cipher_compositiion1(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher(key)
     self.assertEqual(c.decode(c.encode(plaintext)), plaintext)
Ejemplo n.º 27
0
 def test_throws_an_error_with_a_numeric_key(self):
     with self.assertRaisesWithMessage(ValueError):
         Cipher('12345')
 def test_cipher_compositiion2(self):
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher()
     self.assertEqual(c.decode(c.encode(plaintext)), plaintext)
Ejemplo n.º 29
0
 def test_can_decode(self):
     cipher = Cipher()
     self.assertEqual(cipher.decode(cipher.key[0:len("aaaaaaaaaa")]),
                      "aaaaaaaaaa")
 def test_cipher_wrong_key(self):
     with self.assertRaises(ValueError):
         Cipher('a1cde')
     with self.assertRaises(ValueError):
         Cipher('aBcde')
Ejemplo n.º 31
0
 def test_can_decode(self):
     cipher = Cipher()
     plaintext = 'aaaaaaaaaa'
     self.assertEqual(cipher.decode(cipher.key[:len(plaintext)]), plaintext)
Ejemplo n.º 32
0
 def test_can_encode(self):
     cipher = Cipher()
     self.assertEqual(cipher.encode('aaaaaaaaaa'), cipher.key[:10])
Ejemplo n.º 33
0
 def test_can_decode(self):
     cipher = Cipher('abcdefghij')
     self.assertEqual(cipher.decode(cipher.key), 'aaaaaaaaaa')
Ejemplo n.º 34
0
 def test_can_decode(self):
     cipher = Cipher()
     plaintext = 'aaaaaaaaaa'
     self.assertEqual(cipher.decode(cipher.key[:len(plaintext)]), plaintext)
Ejemplo n.º 35
0
 def test_can_double_shift_encode(self):
     plaintext = 'iamapandabear'
     cipher = Cipher(plaintext)
     self.assertEqual(cipher.encode(plaintext), 'qayaeaagaciai')
Ejemplo n.º 36
0
 def test_key_is_only_made_of_lowercase_letters(self):
     self.assertIsNotNone(re.match('^[a-z]+$', Cipher().key))
Ejemplo n.º 37
0
 def test_can_handle_messages_longer_than_key(self):
     cipher = Cipher('abc')
     self.assertEqual(cipher.encode('iamapandabear'), 'iboaqcnecbfcr')
Ejemplo n.º 38
0
 def test_can_encode(self):
     cipher = Cipher('abcdefghij')
     self.assertEqual(cipher.encode('aaaaaaaaaa'), cipher.key)
Ejemplo n.º 39
0
 def test_cipher_encode3(self):
     c = Cipher('dddddddddddddddddddddd')
     self.assertEqual('yhqlylglylfl', c.encode('venividivici'))
Ejemplo n.º 40
0
 def test_can_decode(self):
     cipher = Cipher('abcdefghij')
     self.assertEqual(cipher.decode(cipher.key), 'aaaaaaaaaa')
Ejemplo n.º 41
0
 def test_cipher_encode_short_key(self):
     c = Cipher('abcd')
     self.assertEqual('abcdabcd', c.encode('aaaaaaaa'))
Ejemplo n.º 42
0
 def test_is_reversible(self):
     cipher = Cipher('abcdefghij')
     plaintext = 'abcdefghij'
     self.assertEqual(cipher.decode(cipher.encode(plaintext)), plaintext)
Ejemplo n.º 43
0
 def test_cipher_compositiion2(self):
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher()
     self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
Ejemplo n.º 44
0
 def test_encode_letter_with_default_shift_distance(self):
     cipher = Cipher()
     plaintext = 'a'
     ciphertext = 'b'
     self.assertEqual(ciphertext, cipher.encode(plaintext))