2
$\begingroup$

I'm working on a project where I'm trying to decipher an input text using frequency analysis. So far I've added first letter frequencies, common bigrams, double letter frequencies, as well as single letter frequencies.

An issue I'm running into is finding a way to calculate a sort of threshold for single letter frequencies. For example, my frequency for the letter 'e' is 12.02. Now when i enter the phrase "hello world" as a cipher "zkppo worpd", the letter frequency for what should be 'e' is roughly 9. Using just the letter frequencies from the array, it would therefore convert the 'k' to a 't'. I was wondering if there was any sort of algorithm I could use to give the letter frequencies a threshold based off of the length of input string.

If you guys would want to look at the code, the link is here.

$\endgroup$
1
  • 1
    $\begingroup$ Note: You might be better of asking this on Cryptography Stack Exchange: crypto.stackexchange.com I think you're looking at this the wrong way (as I did when I was playing around with this). You shouldn't be trying to match frequencies, you should try to match order. Instead of saying 'Whichever letter appears roughly 12% of the time is e', say 'Whichever letter appears the most common is e'. You can then use the expected and actual percentages to calculate an accuracy score for you algorithm, this should allow you to easily test and improve your algorithm. $\endgroup$
    – shmoo6000
    Sep 17, 2018 at 8:06

1 Answer 1

1
$\begingroup$

Frequency analysis is useful for breaking a substitution cipher, but even there, the frequency analysis must be combined with tests that actually check to see if substitution of letters leads to a meaningful change from ciphertext to plaintext. In your example using the ciphertext "zkppo worpd", an appropriate frequency-based algorithm would start running through common substitutions (based on the frequency analysis) until there is a substitution to a meaningful plaintext. Especially for short messages, when there is not much data to go by in the message, the frequency analysis will typically run through some incorrect substitutions before it gets to the correct substitution that yields a meaningful conversion to plaintext. If you want to create an algorithm that automates this process then it is going to need a step where it examines a proposed substitution against a dictionary of words to see if the substitution is yielding meaningful words or not.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.