Skip to content

Instantly share code, notes, and snippets.

@martani
Created April 27, 2011 19:18
Show Gist options
  • Save martani/944969 to your computer and use it in GitHub Desktop.
Save martani/944969 to your computer and use it in GitHub Desktop.
Vegenere Decipher
static string DecipherVeginere(string text, string key)
{
StringBuilder result = new StringBuilder();
int keyLength = key.Length;
int diff;
char decoded;
for (int i = 0; i < text.Length; i++)
{
diff = text[i] - key[i%keyLength];
//diff should never be more than 25 or less than -25
if(diff < 0)
diff += 26;
decoded = (char)(diff + 'a') ;
result.Append(decoded);
}
return result.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment