A Java solution for a university cryptography assignment, implementing Known Plaintext (KPA) and Ciphertext-Only (COA) attacks on an 8-rotor cipher. 🔒

This repository contains the solution code and data for the Cryptography and Secure Development (CSD) midterm. It demonstrates two attacks against an 8-rotor substitution-permutation style machine: a Known Plaintext Attack (KPA) and a Ciphertext-Only Attack (COA).
KPA.java — Known Plaintext Attack implementation (dictionary search).COA.java — Ciphertext-Only Attack implementation (scoring + dictionary search).Rotor96Crypto.java — 8-rotor encryption/decryption engine used by both attacks.CSVReader.java — CSV helper used to load student ciphertexts.passwords — dictionary of candidate keys (one per line).ciphertext1.txt — ciphertext for the KPA task.ciphertext2.txt — ciphertext for the COA task.decrypted_results.txt — output generated by KPA.java (found key + plaintext).password_scores.csv — scoring output generated by COA.java for analysis.report.pdf / report.tex — written report with methodology, calculations, and results.Midterm_Assignment.pdf — assignment brief.passwords list. Decrypt ciphertext1.txt with each key and check for the known prefix ("We"). The key giveme was recovered; the plaintext is in decrypted_results.txt.passwords list. For each candidate key, decrypt ciphertext2.txt and score the result using English-language statistics (letter frequency and n-gram scores). The highest-scoring plaintext corresponds to the key octopus.giveme. The full decrypted message (checked for the student ID 3043047J) is written to decrypted_results.txt.octopus. The decrypted plaintext includes a timestamp and the student identifier; COA.java also writes per-key scores to password_scores.csv for analysis.Notes:
KPA.java (checking full plaintext coherence and the student ID) disambiguate candidates.report.pdf / report.tex for detailed derivations, plots, and the scoring algorithm used by COA.java.javac KPA.java COA.java Rotor96Crypto.java CSVReader.java
ciphertext1.txt:java KPA
decrypted_results.txt will be created/updated and contains the discovered key and plaintext.ciphertext2.txt and generate scores:java COA
password_scores.csv is written with per-key scores (useful for analysis and plotting).Tips
passwords file, increase heap size, e.g.:java -Xmx2G COA
passwords file and ciphertexts to reproduce results in the report. Running COA will produce password_scores.csv which contains the per-password scoring data used for analysis (e.g., to estimate unicity distance and score separability).report.pdf contains derivations for the expected number of keys matching a known-plaintext prefix (KPA) and the unicity distance estimates used to reason about the COA.COA.java combines letter frequency and n-gram statistics; inspect the source to tune weights or add a language model.passwords and running multiple JVM instances or by modifying COA.java to use a thread pool.Rotor96Crypto with a known key/plaintext pair to validate encryption/decryption round-trips.passwords or the ciphertext files, ensure you run from the repository root where those files live.passwords file and ciphertext files from this repository.The attached report.pdf documents the approach and results. High-level findings:
giveme was recovered reliably. The report derives the probability of multiple keys matching the known-prefix and shows it is negligible for the chosen dictionary size.octopus. password_scores.csv demonstrates a clear score separation for this dataset, and the report discusses unicity distance calculations that explain why the plaintext is recoverable from the ciphertext alone with high probability.For full details (math, code excerpts and plots), see report.pdf and the LaTeX source report.tex.
If you'd like, I can:
Rotor96Crypto round-trips; orCOA.java to run in parallel and add a simple script to split the passwords file for easy parallel runs.If you want me to commit this README change, confirm and I'll finalize the update and mark the task completed.
Stars
0
Forks
0
Watchers
1
Primary Language
TeX