A classical, poly-alphabetic cipher. Created by Blaise de Vigenère. Provides higher security than the Bellaso variant. This was NOT covered in the class; only included here for the sake of completeness.
You may find an implementation of Autokey cipher in sahithyandev/ciphers.
Encryption
A short secret key is used to encrypt only the first few characters of the plaintext. From there, the keystream continues with the plaintext itself, shifted by the key length, rather than repeating the short key.
Each position adds its keystream letter modulo .
Since the keystream is never a short repeating sequence, the Kasiski test cannot be used to find a key length, making this cipher more secure than the repeating-key (Bellaso) variant.
Decryption
Only the short primer key is known at the start. Each position subtracts its keystream letter modulo . Every recovered plaintext letter is appended to the keystream and used to decrypt a later position, so the keystream is rebuilt as decryption proceeds.
Attacking
Still vulnerable to statistical attacks, since the key length is typically much shorter than the message, so most of the keystream is plaintext of the same language, whose letter frequencies are known.
The primer is short, so its length is guessed and each value tried.
For a fixed , every position past the primer has keystream equal to the plaintext places earlier, so
Here is the numeric value of the -th ciphertext letter and likewise for plaintext. to .
Applying repeatedly walks back in steps of until it hits the primer:
where is the one primer letter in residue class . Each of the classes is then fixed by a single unknown letter. Its 26 values are tried and the one whose column matches the language’s letter frequencies is kept. The correct makes all columns come out as the language. No probable word is needed.
Worked Example
Plaintext imakemyownluck under primer key PATRIC, with to .
The keystream is the primer key followed by the plaintext itself, truncated to the plaintext length.
plaintext: i m a k e m y o w n l u c k
keystream: P A T R I C I M A K E M Y O
ciphertext: X M T B M O G A W X P G A Y
Each position adds the keystream letter modulo .
Ciphertext is XMTBMOGAWXPGAY.
For decryption, only the primer key PATRIC is known at the start. Each recovered plaintext letter is appended to the keystream and used to decrypt later positions.
After 6 positions the primer key is exhausted and the keystream continues with the recovered plaintext imakem.
Plaintext is imakemyownluck.
For the attack, take ciphertext UIHGTQANBLIGBBRBPRB with . Class holds positions with ciphertext values . As a function of the unknown primer letter , the class decrypts to
Only (B) gives language: t n n y. The other 2 classes resolve the same way, giving primer BUZ and plaintext toinfinityandbeyond.