title: How do I write an algorithm to break the Caesar Cipher?
body: <p>I'm trying to do an exercise in a programming book, one of the exercises being decrypting ciphertext that uses the <a href="http://en.wikipedia.org/wiki/Caesar_cipher" rel="nofollow">Caesar cipher</a> with an unknown shift.</p>
  
  <p>Here's the ciphertext:</p>
  
  <blockquote>
    <p><code>HVWGWGHVSPSGHQCADIHSFSLSFQWGSWVOJSSJSFSLDSFWSBQSR</code></p>
  </blockquote>
  
  <p>I don't know the expected output because I haven't determined the algorithm yet.</p>
  
  <p>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#?</p>
  
  <pre><code>string s = "HVWGWGHVSPSGHQCADIHSFSLSFQWGSWVOJSSJSFSLDSFWSBQSR";
  
  int[] freq = new int[26];
  
  for (int i = 0; i &lt; 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 &lt; 26; i++)
  {
    Console.WriteLine(i + " " + freq[i]);
  }
  </code></pre>