This script decrypts a Vigenère cipher using frequency analysis. It includes functions to estimate the key length, perform frequency analysis, and decrypt the ciphertext.
- Kasiski Examination: Estimates the length of the Vigenère key.
- Frequency Analysis: Analyzes letter frequencies to determine the most likely key.
- Decryption: Uses the derived key to decrypt the ciphertext.
- Calculate Index of Coincidence (IC):
- The calculate_ic function computes the IC for a given text segment to help identify the key length.
- Kasiski Examination:
- The
kasiski_examination
function calculates the IC for various assumed key lengths to identify the most probable key lengths.
- The
- Frequency Analysis:
- The
frequency_analysis
function analyzes the frequency of each letter in segments of the ciphertext to determine the most likely shift for each segment.
- The
- Decrypt Vigenère Cipher:
- The
decrypt_vigenere
function uses the derived key to decrypt the entire ciphertext.
- The
-
Set the Ciphertext: Replace the
ciphertext
variable with your Vigenère encrypted message. -
Estimate Key Length:
- The script uses Kasiski examination to estimate the key length and prints the top 5 key length estimates.
-
Decrypt the Ciphertext:
- The script performs frequency analysis for each estimated key length, derives the key, and decrypts the ciphertext.