Cipher CTF Challenge Generator (Gronsfeld Cipher)Press the blue button to regenerate a Gronsfeld cipher challenge. The Gronsfeld cipher is similar to the Vigenere cipher, but we use numerics values to perform the shift of letters, rather than a character key. |
Coding
The Gronsfeld cipher is similar to the Vigenere cipher, but we use numerics values to perform the shift of letters, rather than a character key. For example, "applecore" with a key of "12345" becomes:
applecore brspjdqui
and where 'a' is shifted by 1 to get a 'b', and 'p' shifted by 2 gives an 'r'.
The basic coding in C# is:
public static string getGronsfeld(string s,string key) { s = s.ToLower(); string rtn = ""; var count = 0; foreach (char ch in s) { try { if (ch == ' ') rtn = rtn + " "; else if (ch >= 'a' && ch <= 'z') { var shift = Char.GetNumericValue(key[count % key.Length]); rtn = rtn + (char) ( ( ( (int)ch-(int)'a' +shift ) % 26 ) +(int)'a' ); count++; } } catch (Exception ex) { } } return (rtn); }