0
$\begingroup$

So basically I was implementing a decryption tool (just for fun) and the first encryption logic I decided to implement was Caesar Cipher. So if I have the input as cvggbmp and I have to find what the cleartext is, I would pass this through the decrypt function 26 times. I get 26 outputs. Is there some way I match each of these outputs against a words.txt for like legible word density and then display the output with the most number of legible words ? Or is there a better optimized way to do this ?

$\endgroup$
7
  • $\begingroup$ In GNU development tools, there is a strings command that is very helpful for such cases, though for Shift Cipher this is more costly than just printing and looking at all possible outputs. Note that the key in the Caesar cipher is fixed. The shift cipher has all possible shifts in which one may exclude the identity! Caesar cipher is a shift cipher with the key is fixed to 3. $\endgroup$ – kelalaka May 17 at 9:49
  • $\begingroup$ I was of the understanding that Caesar Cipher is where we shift each character by n. Thanks for clarifying anyways. $\endgroup$ – Aritro Shome May 17 at 10:05
  • $\begingroup$ @kelalaka is there some sort of a dictionary ( not dict data structure) using which I can compare whether a word is a legible english word or gibberish ? $\endgroup$ – Aritro Shome May 17 at 10:06
  • $\begingroup$ Little search? github.com/dwyl/english-words $\endgroup$ – kelalaka May 17 at 10:15
  • $\begingroup$ @kelakala thanks. GitHub wasn't opening on my device. Now it is ok. $\endgroup$ – Aritro Shome May 17 at 11:28
0
$\begingroup$

Is there some way I match each of these outputs against a words.txt for like legible word density and then display the output with the most number of legible words ?

This is a good way to start. Better yet to use several methods from the fastest to slower ones to make the test more reliable.

One of the faster methods can be the use of "zero bigrams" method - just find a set of bigrams that invalid for natural text on your language e.g. zero frequency bigrams. If you've got some number of them in a decrypted text you can reject the text as invalid.

The slower method is to use some statistical test. For instance you can use chi squared test on bigrams or N-grams to tell their distribution in natural text from the distribution in the encrypted text.

$\endgroup$
1
  • 1
    $\begingroup$ Seems like I have to learn a lot....Thanks for the info anyways. $\endgroup$ – Aritro Shome May 19 at 5:12
0
$\begingroup$

A simple approach is to do char gram frequencies. There are readily downloadable dictionaries of char-gram frequencies. You can lookup each set of consecutive characters of the requested length and multiply the probabilities. For numerical reasons you don't actually multiply probabilities but sum the logarithms. You probably want to use some minimal frequency to prevent multiplying be zero.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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