16,018,534 members

See more:

Im trying to do an exercise in a programming book, one of the exercises being decrypting ciphertext that uses the Caesar cipher with an unknown shift.

Here is the ciphertext:

HVWGWGHVSPSGHQCADIHSFSLSFQWGSWVOJSSJSFSLDSFWSBQSR

I don't know the expected output because I haven't determined the algorithm yet.

I've written the following algorithm to try to decrypt it using the Caesar cipher, but this is as far as I've gotten. How do I decrypt this in C#?

**What I have tried:**

Here is the ciphertext:

HVWGWGHVSPSGHQCADIHSFSLSFQWGSWVOJSSJSFSLDSFWSBQSR

I don't know the expected output because I haven't determined the algorithm yet.

I've written the following algorithm to try to decrypt it using the Caesar cipher, but this is as far as I've gotten. How do I decrypt this in C#?

C#

string s = "HVWGWGHVSPSGHQCADIHSFSLSFQWGSWVOJSSJSFSLDSFWSBQSR"; int[] freq = new int[26]; for (int i = 0; i < s.Length; i++) { // converting string temp = s.Substring(i, 1); // converting to an array int itemp = (int)temp.ToCharArray()[0]; freq[itemp - 65]++; } for (int i = 0; i < 26; i++) { Console.WriteLine(i + " " + freq[i]); }

Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

http://stackoverflow.com/questions/17688958/how-do-i-write-an-algorithm-to-break-the-caesar-cipher

It also has the answer:

THISISTHEBESTCOMPUTEREXERCISEIHAVEEVEREXPERIENCED