Cssexp
Cssexp
cipher_text = ""
for char in plaintext:
if char.isalpha():
shift = key % 26
if char.islower():
cipher_text += chr((ord(char) - ord('a') + shift) % 26 + ord('a'))
elif char.isupper():
cipher_text += chr((ord(char) - ord('A') + shift) % 26 + ord('A'))
else:
cipher_text += char
return cipher_text
def main():
print("Choose Cipher Type:")
print("1. Additive Cipher")
print("2. Multiplicative Cipher")
print("3. Autokey Cipher")
if cipher_choice == 1:
key = int(input("Enter the additive key (integer): "))
encrypted_text = additive_cipher(plaintext, key)
decrypted_text = decrypt_additive_cipher(encrypted_text, key)
print(f"\nPlaintext: {plaintext}")
print(f"Encryption (Additive Cipher) Text: {encrypted_text}")
print(f"Decryption (Additive Cipher) Text: {decrypted_text}")
print(f"Key: {key}")
elif cipher_choice == 2:
key1, key2 = 7, 15
encrypted_text = multiplicative_cipher(plaintext, key1, key2)
decrypted_text = decrypt_multiplicative_cipher(encrypted_text, key1, key2)
print(f"\nPlaintext: {plaintext}")
print(f"Encryption (Multiplicative Cipher) Text: {encrypted_text}")
print(f"Decryption (Multiplicative Cipher) Text: {decrypted_text}")
print(f"Key pair: ({key1}, {key2})")
elif cipher_choice == 3:
key = input("Enter the autokey (string): ")
encrypted_text = autokey_cipher(plaintext, key)
decrypted_text = decrypt_autokey_cipher(encrypted_text, key)
print(f"\nPlaintext: {plaintext}")
print(f"Encryption (Autokey Cipher) Text: {encrypted_text}")
print(f"Decryption (Autokey Cipher) Text: {decrypted_text}")
print(f"Key: {key}")
else:
print("Invalid choice, please try again.")
if __name__ == "__main__":
main()
OUTPUT-
Plaintext: hello
Encryption (Additive Cipher) Text: khoor
Decryption (Additive Cipher) Text: hello
Key: 3
Plaintext: goodbye
Encryption (Multiplicative Cipher) Text: oyhhfli
Decryption (Multiplicative Cipher) Text: goodbye
Key pair: (7, 15)
Plaintext: world
Encryption (Autokey Cipher) Text: xqpvi
Decryption (Autokey Cipher) Text: world
Key: key