This is a project for Functional and Logic Programming course. It is an application written in Haskell programming language for deciphering monoalphabetic substitution cipher by ciphertext-only attack. It works as follows:
- Frequency analysis on letters in ciphertext is performed.
- If some letters are missing in ciphertext, they are added with zero frequency
- Mapping of ciphertext letters to plaintext letters is created according to frequency database -> letter key
- Frequency analysis on digrams in ciphertext is performed.
- Mapping of ciphertext digrams to plaintext digrams is created according to frequency database, this is then converted to mapping of letter to letter -> digram key
- Letter key and digram key are combined, when ciphertext letters match, digram key has priority, so its plaintext is used
- Frequency analysis on trigrams in ciphertext is performed.
- Mapping of ciphertext trigrams to plaintext trigrams is created according to frequency database, this is then converted to mapping of letter to letter -> trigram key
- Existing key (combined letter and digram keys) and trigram key are combined, when ciphertext letters match, trigram key has priority, so its plaintext is used -> final key
- Final key is modified so it does not contain two ciphertext letters mapping to the same plaintext letter, if some ciphertext letters do not have a plaintext letter mapping, '-' is used.
Usage: ./subs-cipher [-k] [-t] frequency_database [ciphertext]
- -k output key
- -t output deciphered text
- frequency_database file containing frequency database
- [ciphertext] file containing frequency database, stdin is used if missing