1
votes

I am trying to make a program which can help you to break a cipher text without knowing the plain text and the key.

I want probable plain text at the output which gives the closest statistical values and a set of probable candidates keys

I started doing the frequency analysis,completed it. It helped me in telling the occurrence of each alphabet, but I have no idea how will I generate keys from that.

class Program
{
     static void Main()
     {
         // Array to store frequencies.
         int[] c = new int[(int)char.MaxValue];


         // Read entire text file.
            string s = File.ReadAllText("text.txt");


          // Iterate over each character.
          foreach (char t in s)
            {
            // Increment table.
            c[(int)t]++;
         }


          // Write all letters found.
         for (int i = 0; i < (int)char.MaxValue; i++)
         {
            if (c[i] > 0 &&
            char.IsLetterOrDigit((char)i))
            {
            Console.WriteLine("Letter: {0}  Frequency: {1}",
                (char)i,
                c[i]);
            }
         }
    }
}
2
You'll probably die of old age before the program breaks the first encrypted string.x13
@artjomB. i have added the code,kindly review.Waqas Amjad
If it was that easy to Decipher without key then know one would used this encryption technique in first place. What you are looking for some kind of brute force program which may take up years before you get any results..Why you want to do this? Why are you working on such program? What problem will your program solves?Viru
There is too much information missing to help you in any meaningful way. What cipher was used (classical like caesar or modern like AES)? What results did you achieve so far (please show some data)? Do you know what kind of data is supposed to be in there (textual or binary)?Artjom B.
to be fair, it could be interesting to prove for someone who is just entering the domain. Hardly seems like a threat, and if it is a real wannabe warez writer, I feel safe :)Shawn Mehan

2 Answers

2
votes

A Caesar cipher just replaces each plain text character with one a fixed number of places away down the alphabet. Assuming no casing, and English text, then it is trivial to produce all possible 26 decryptions and just pick out the correct one by eye.

For a substitution cipher you need to generalise your solution. A simplified method is to do a frequency count as you've suggested, and sort characters in descending order of frequency. Map those to the letters (again for English) ETAOINSRHOLUCMFYWGPBVKXQJZ (so for example assume the most frequent character represents an E, the next most frequent a T and so on). Use the mapping to do the decryption. The more cipher text you have the better the decryption will be. It is unlikely to be completely accurate but will give you enough information to fill in the gaps manually.

A more sophisticated solution might generate the mapping from the frequency distribution rather than just the sort order, and use known facts about the language e.g. Q is usually followed by U. You can get really fancy and check digraph and and trigram frequencies: http://practicalcryptography.com/cryptanalysis/letter-frequencies-various-languages/english-letter-frequencies/

0
votes

For a simple letter-substitution cipher, you would want to get a list of letter frequencies in English and try to map them to the most frequent letters in the message. Note that. back before computers, real militaries inserted irrelevant text into messages to throw this off. A strategy cryptographers used, back in those days, was to look for longer repeated strings. In English, they looked for three-letter words like and, the, not or for. In German, they looked for long compound words like the name of the headquarters a unit was reporting to, or tried to guess what weather report it would have sent at a given location and time.