Competition 1 - Code Cracker
About this Project
This is my entry for Competition 1 of CM1210 Object-Oriented Programming with Java.
The task was given a "ciphertext":
ETEVHTWGSAHGWYVPNKQOEGWYVPNKPDEPHWAOVWPFWNHANEVWXAVOAEAJEUXTAOWBTEVHTWGSAHGWYVPNQAOQVGTYHAVAXETOANFQEOIQPLANTEVHFYNSQVEBEOWSKNCKLOPEVTYJAUFWYNCOTWZESQEPERQSQOPEVYCEVHEGDEHEVHEYOPNQEEHWYFTKTEVHTWGSAHGWYVPNKQOWVAPDEPWVTKFWNHANOTEVHTWGSAHGWYVPNQAOPDANAENAWVTKPIWHWYFTKTEVHTWGSAHGWYVPNQAOQVPDAIWNTHWVAWBPDAUQOYLFASQOPEVIDEPQOPDAWPDANWVA
Of which a part of it decrypts to this "phrase":
NEPALSERBIASWITZERLANDBURKINAFASOKYRGYZSTANLUXEMBOURGSLOVAKIATAJIKISTANUGANDACHADANDAUSTRIA
(NEPAL, SERBIA, SWITZERLAND, BURKINA FASO, KYRGYZSTAN, LUXEMBOURG, SLOVAKIA, TAJIKISTAN, UGANDA, CHAD AND AUSTRIA)
Create a java program to decrypt the entire cipher text to reveal a question and email the answer to the question to the task setter.
The only clue given was that the cipher used was a substitution cipher with no repeats.
My Solution
I created a Maven project using Google's Guava Library and JavaFX Library to create my solution.
My solution involved chopping up the "ciphertext" into lots of snippets the same length as the "phrase". I then created a for each version of the ciphertext named "subtext" out of numbers. This list was created by assigning the first letter to appear the number 1, then if the next letter was different it got given the number 2, if a letter repeats it would get the same number as previously allocated.
This gave me a bunch of number lists with each number representing a different letter. I then compared these lists of numbers to the number pattern of the "phrase" and when 2 of these matched it meant they had the same letter layout.
Lastly I had to create a key using a map where the letter number 1 represented in "phrase" mapped to the letter number 1 represented in "subtext". Any missing letters were then filled in automatically, as there was only 1 missing letter in each set.
Lastly using this key I decrypted the "ciphertext" to get the question and work out the answer.