# How to approach cipher decoding using frequency analysis

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.

• 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. Sep 17, 2018 at 8:06