コード例 #1
0
 def test_cipher_wrong_key(self):
     with self.assertRaisesWithMessage(ValueError):
         Cipher('a1cde')
     with self.assertRaisesWithMessage(ValueError):
         Cipher('aBcde')
コード例 #2
0
 def test_decode_string_with_default_shift_distance(self):
     cipher = Cipher()
     plaintext = 'xyzabcde'
     ciphertext = 'wxyzabcd'
     self.assertEqual(ciphertext, cipher.decode(plaintext))
コード例 #3
0
 def test_encode_with_26_shift_distance(self):
     cipher = Cipher()
     plaintext = 'abcdefghij'
     ciphertext = 'abcdefghij'
     self.assertEqual(ciphertext, cipher.encode(plaintext, 26))
コード例 #4
0
 def test_decode_raise_error_if_non_letter_characters(self):
     cipher = Cipher()
     plaintext = 'az4'
     with pytest.raises(Exception):
         cipher.decode(plaintext)
コード例 #5
0
 def test_encode_wraps_z_to_a(self):
     cipher = Cipher()
     plaintext = 'z'
     ciphertext = 'a'
     self.assertEqual(ciphertext, cipher.encode(plaintext))
コード例 #6
0
 def test_can_encode_messages_longer_than_the_key(self):
     cipher = Cipher("abc")
     plaintext = "iamapandabear"
     self.assertEqual(cipher.encode(plaintext), "iboaqcnecbfcr")
コード例 #7
0
 def test_can_encode(self):
     cipher = Cipher()
     plaintext = "aaaaaaaaaa"
     self.assertEqual(cipher.encode(plaintext),
                      cipher.key[0:len(plaintext)])
コード例 #8
0
 def test_cipher_encode_short_key(self):
     c = Cipher('abcd')
     self.assertEqual('abcdabcd', c.encode('aaaaaaaa'))
コード例 #9
0
 def test_decode_with_27_shift_distance(self):
     cipher = Cipher()
     plaintext = 'xyzabcde'
     ciphertext = 'wxyzabcd'
     self.assertEqual(ciphertext, cipher.decode(plaintext, 27))
コード例 #10
0
 def test_cipher_encode2(self):
     c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
     self.assertEqual('itisawesomeprogramminginpython',
                      c.encode('itisawesomeprogramminginpython'))
コード例 #11
0
 def test_cipher_encode3(self):
     c = Cipher('dddddddddddddddddddddd')
     self.assertEqual('yhqlylglylfl', c.encode('venividivici'))
コード例 #12
0
 def test_cipher_compositiion2(self):
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher()
     self.assertEqual(c.decode(c.encode(plaintext)), plaintext)
コード例 #13
0
 def test_cipher_compositiion1(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher(key)
     self.assertEqual(c.decode(c.encode(plaintext)), plaintext)
コード例 #14
0
 def test_cipher_encode4(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     c = Cipher(key)
     self.assertEqual(c.encode('diffiehellman'), 'gccwkixcltycv')
コード例 #15
0
 def test_can_wrap_on_encode(self):
     cipher = Cipher("abcdefghij")
     plaintext = "zzzzzzzzzz"
     self.assertEqual(cipher.encode(plaintext), "zabcdefghi")
コード例 #16
0
 def test_encode_always_returns_downcase_string(self):
     cipher = Cipher()
     plaintext = 'AbCdEfGhIj'
     ciphertext = 'bcdefghijk'
     self.assertEqual(ciphertext, cipher.encode(plaintext))
コード例 #17
0
 def test_can_wrap_on_decode(self):
     cipher = Cipher("abcdefghij")
     self.assertEqual(cipher.decode("zabcdefghi"), "zzzzzzzzzz")
コード例 #18
0
 def test_can_decode(self):
     cipher = Cipher()
     self.assertEqual(cipher.decode(cipher.key[0:len("aaaaaaaaaa")]),
                      "aaaaaaaaaa")
コード例 #19
0
 def test_can_decode_messages_longer_than_the_key(self):
     cipher = Cipher("abc")
     self.assertEqual(cipher.decode("iboaqcnecbfcr"), "iamapandabear")
コード例 #20
0
 def test_key_is_made_only_of_lowercase_letters(self):
     self.assertIsNotNone(re.match("^[a-z]+$", Cipher().key))
コード例 #21
0
 def test_decode_always_returns_downcase_string(self):
     cipher = Cipher()
     plaintext = 'BcDeFgHiJk'
     ciphertext = 'abcdefghij'
     self.assertEqual(ciphertext, cipher.decode(plaintext))
コード例 #22
0
 def test_can_encode(self):
     cipher = Cipher("abcdefghij")
     plaintext = "aaaaaaaaaa"
     self.assertEqual(cipher.encode(plaintext), cipher.key)
コード例 #23
0
 def test_decode_letter_with_default_shift_distance(self):
     cipher = Cipher()
     plaintext = 'b'
     ciphertext = 'a'
     self.assertEqual(ciphertext, cipher.decode(plaintext))
コード例 #24
0
 def test_can_decode(self):
     cipher = Cipher("abcdefghij")
     self.assertEqual(cipher.decode(cipher.key), "aaaaaaaaaa")
コード例 #25
0
 def test_decode_wraps_a_to_z(self):
     cipher = Cipher()
     plaintext = 'z'
     ciphertext = 'a'
     self.assertEqual(ciphertext, cipher.decode(plaintext))
コード例 #26
0
 def test_is_reversible(self):
     cipher = Cipher("abcdefghij")
     plaintext = "abcdefghij"
     self.assertEqual(cipher.decode(cipher.encode(plaintext)), plaintext)
コード例 #27
0
 def test_decode_with_10_shift_distance(self):
     cipher = Cipher()
     plaintext = 'ghijklmn'
     ciphertext = 'wxyzabcd'
     self.assertEqual(ciphertext, cipher.decode(plaintext, 10))
コード例 #28
0
 def test_can_double_shift_encode(self):
     cipher = Cipher("iamapandabear")
     plaintext = "iamapandabear"
     self.assertEqual(cipher.encode(plaintext), "qayaeaagaciai")
コード例 #29
0
 def test_decode_with_26_shift_distance(self):
     cipher = Cipher()
     plaintext = 'klmnopqrst'
     ciphertext = 'klmnopqrst'
     self.assertEqual(ciphertext, cipher.decode(plaintext, 26))
コード例 #30
0
 def test_throws_an_error_with_empty_key(self):
     with self.assertRaisesWithMessage(ValueError):
         Cipher('')