def encrypt_msg(str_entry, default_key, textbox): user_input = str_entry.get() key = default_key.get() alpha_capital = (list(string.ascii_uppercase)) alpha_lower = (list(string.ascii_lowercase)) # puts the message in a label or textbox msg = caesar.encrypt_caesar(alpha_capital, alpha_lower, user_input, key) textbox.config(text=msg)
def test_randomized(self): shift = random.randint(8, 24) plaintext = "".join( random.choice(string.ascii_letters + " -,") for _ in range(64)) ciphertext = caesar.encrypt_caesar(plaintext, shift=shift) self.assertEqual( plaintext, caesar.decrypt_caesar(ciphertext, shift=shift), msg=f"shift={shift}, ciphertext={ciphertext}", )
class CaesarTestCase(unittest.TestCase): def test_encrypt(self): cases = [('', 0, ''), ('python', 0, 'python'), ('Python', 0, 'Python'), ('PYTHON', 0, 'PYTHON'), ('Python3.6', 0, 'Python3.6'), ('', 3, ''), ('python', 3, 'sbwkrq'), ('Python', 3, 'Sbwkrq'), ('PYTHON', 3, 'SBWKRQ'), ('Python3.6', 3, 'Sbwkrq3.6')] for i, (plaintext, shift, chiphertext) in enumerate(cases): with self.subTest(case=i, plaintext=plaintext, chiphertext=chiphertext): self.assertEqual(chiphertext, caesar.encrypt_caesar(plaintext, shift=shift))
class CaesarTestCase(unittest.TestCase): def test_encrypt(self): cases = [ ("", 0, ""), ("python", 0, "python"), ("PYTHON", 0, "PYTHON"), ("Python", 0, "Python"), ("Python3.6", 0, "Python3.6"), ("", 3, ""), ("PYTHON", 3, "SBWKRQ"), ("python", 3, "sbwkrq"), ("Python", 3, "Sbwkrq"), ("Python3.6", 3, "Sbwkrq3.6"), ] for i, (plaintext, shift, chiphertext) in enumerate(cases): with self.subTest(case=i, plaintext=plaintext, chiphertext=chiphertext): self.assertEqual(chiphertext, caesar.encrypt_caesar(plaintext, shift=shift))
curdir = os.getcwd() i = input('Caesar cipher key: ') playfair_key = input('Play Fair Cipher: ') vigenere_mode = int(input('Enter Vigenere Cipher mode: 1 for auto 0 for repetition: ')) vigenere_key = input('Vigenere Cipher key: ') hill_key = input('Hill cipher key: ').split(' ') # hill_key_2 = np.array([[5,17],[8,3]]) # hill_key_3 = np.array([[2,4,12],[9,1,6],[7,5,3]]) vernam_key = np.frombuffer(input('Vernam cipher key: ').encode(), np.uint8) os.chdir('Classical Ciphers\Input Files\Caesar') with open("caesar_plain.txt", 'r') as f: plainText = f.readlines() caesar_cipherText = encrypt_caesar(plainText, key=int(i)) os.chdir(curdir) os.chdir('Classical Ciphers\Input Files\PlayFair') with open("playfair_plain.txt", 'r') as f: plainText = f.readlines() playfair_cipherText = encrypt_playfair(plainText, playfair_key) os.chdir(curdir) os.chdir('Classical Ciphers\Input Files\Vigenere') with open("vigenere_plain.txt", 'r') as f: plainText = f.readlines() vigenere_cipherText = encrypt_vigenere(plainText, vigenere_key, mode=vigenere_mode) os.chdir(curdir) os.chdir('Classical Ciphers\Input Files\Hill')