Created
April 27, 2011 19:18
-
-
Save martani/944969 to your computer and use it in GitHub Desktop.
Vegenere Decipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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