This project is an implementation of the Caesar cipher algorithm in Python. The program allows for text encryption and decryption using a given key, as well as cryptanalysis, which is breaking the cipher without knowing the key, based on letter frequency analysis. It is an ideal project for learning basic cryptographic operations and text analysis.
- Encryption: Encrypts text from the
plain.txtfile using a key (shift) and saves the result tocrypto.txt. - Decryption: Decrypts text from the
crypto.txtfile using a key and saves the result todecrypt.txt. - Cryptanalysis: Attempts to find the key and decrypt the text from the
crypto.txtfile without knowing the key. Breaking the cipher is based on letter frequency analysis, which is one of the simplest cryptanalysis methods. The found key is saved inkey-found.txt, and the decrypted text indecrypt.txt. - Text Preparation: Prepares plaintext by removing non-alphabetic characters and converting the text to lowercase, then saves it to
plain.txt.
The program is run with one of the following arguments:
-p: Prepares the plaintext.-e <key>: Encrypts the text using the specified key (a number from 1 to 25).-d <key>: Decrypts the text using the specified key (a number from 1 to 25).-k: Cryptanalysis.
Usage examples:
python caesar-cipher.py -e 3
python caesar-cipher.py -k
orig.txt: File with the original plaintext (used with the-poption).plain.txt: File with the prepared plaintext.crypto.txt: File with the encrypted text.decrypt.txt: File with the decrypted text.key-found.txt: File with the key found by cryptanalysis.
Author: A. Falkowski | Project created as a programming exercise.