/Affine_Cipher_Encryption-Decryption

This Python program implements the Affine Cipher, a type of substitution cipher, for encrypting and decrypting messages. The Affine Cipher uses a pair of keys, alpha (a) and beta (b), to transform plaintext into ciphertext and vice versa.

Primary LanguagePythonMIT LicenseMIT

Affine Cipher Encryption/Decryption Algorithm

Authors: Leo Martinez III - LinkedIn

Contact: leo.martinez@students.tamuk.edu

Created: Spring 2024


This Python program implements the Affine Cipher, a type of substitution cipher, for encrypting and decrypting messages. The Affine Cipher uses a pair of keys, alpha (a) and beta (b), to transform plaintext into ciphertext and vice versa.

Encryption:

  • The encryption formula is given by: E(x) = (ax + b) mod m, where x is the plaintext letter index, a and b are keys, and m is the alphabet size.
  • The program handles case insensitivity and ignores spaces in the input.
  • The ciphertext is generated by converting each letter of the plaintext using the affine transformation.

Decryption:

  • The decryption formula is given by: D(y) = (a_inv * (y - b)) mod m, where y is the ciphertext letter index, a_inv is the modular multiplicative inverse of a, b is the key, and m is the alphabet size.
  • Similar to encryption, the program handles case insensitivity and ignores spaces in the input.

Usage:

  • The program prompts the user to choose between encryption ('e') or decryption ('d').
  • Users enter alpha (a) and beta (b) values, ensuring they fall within the valid range.
  • GCD (Greatest Common Divisor) checks are performed to ensure valid input.
  • Example values for ciphertext and plaintext are provided for testing purposes.

Note:

  • Program was created in Google Colab with Python 3.9

Everything needed along with additional installation information to run the program will be contained in this folder.

Here is a brief explanation of the items:

  • src: folder that contains the source code python script: main.py (use this file to run the program)
  • README.md: contains most basic information about the project
  • LICENSE: Contains license information in regards to the Github repository

Additionally, ensure the "math" python is properly installed in your virtual environment as the .gcd() method is needed to ensure error checking to assist with decryption integrity.