March 6 2023

Decrypting Cipher Text Encoded Using 8 Rotor Encryption machine

Cryptography is a beautiful subject; it’s full of mystery, thrill, and of course, filled with wonders of joy. So in this blog, I share my experience decoding a cipher text encoded using an 8-rotor encryption machine. So it was just the 2nd of March when I was completing this LinkedIn course on Introduction to cryptography and secure development when I went across moodle(LMS used by the University of Glasgow) to see some of the great content posted by my professor to learn from, suddenly I realized that I have a pending midterm assessment which is due in less than 46 hours roughly. When I read through the description of what I needed to do, I got speechless, as I had almost no idea what I would do, so the professor emailed us two cipher texts which were encoded using this 8-rotor machine code he had uploaded in the portal written in JAVA, other than this he had given us a text file containing roughly 10000(ten thousand) possible keys that could be input to the code to decode the cipher text.

So, as we had multiple keys with us, some random cipher text, and the 8-rotor machine code, we needed to find the right key and decode the cipher text into plain sensible text using the right key. So, one of the best ways to do this would be a brute force ofcourse, though; the interesting fact was that as we already have a set of keys, we can actually use a dictionary attack.

In task one, we already have the information that the first two letters of the plain text will be “T” and “h” this got half of my task done; it seems to be simple while performing the dictionary attack; I just filtered the output for the part where the first and second character is as T and h respectively. Well, I thought that this would be enough, but it wasn’t actually. So I got two possible keys after this and two plain texts; the first one was for sure wrong as it just had the first two characters as ‘Th’ but followed with a string of random characters that make no sense and for sure is not an English sentence. The second one was right as it has the decoded English sentence that makes the right sense. So here I have added another filter just by making another set of words consisting of general terms used in the English language such as as, as, the, we, us, etc. This allowed me to resolve the first task with an ace.

In task two, we didn’t have any characters of the plain text, so it needed more effort and a different approach. The only assumption we were given is the context will only generate an English sentence. Now, being a machine learning person, the first idea that hit my mind was precisely to develop an NLP model that would analyze the language to find the key, but the biggest challenge was that we needed to create a code in java, which is an alien language for me always(Ps- I just don’t know why I never liked it, maybe because of its syntax). So I had to think of another way which must be straightforward as by that time I was hardly left with 23 hours, and I needed to do some calculations and produce a report as well besides the code. Well, so what I did is simply browsed google for the average number of lengths of English words(which is almost 4.7 characters), and I replaced the filter for checking to check the average of the set of words in the generated plain text and wohhaa it worked right 🙂

Finally, with all my findings, I completed the report and the complete Midterm assessment to save myself from failing the subject just 3 hours before the deadline 😉