Cipher CTF Challenge Generator (Wolseley Cipher)Press the blue button to regenerate a Wolseley cipher challenge. This cipher was used by Lord commander Garnet Joseph Wolseley in the 18th century, but its author remains unknown. With the Wolseley cipher we use a reversible substitution cipher and where the substitution alphabet is created from a key, and where the ciphertext mapping is a reverse of this. |
Coding
With the Wolseley cipher we use a reversible substitution cipher and where the substitution alphabet is created from a key, and where the ciphertext mapping is a reverse of this. Overall it uses a 25 character alphabet, and where "j" is replaced with an "i". For a word of "forehead" and a key of biometric, we generate a plaintext alphabet from the key of:
BIOMETRCADFGHJKLNPQSUVWXYZ
and where we take the characters from the key first, and then the rest of the alphabet. Note that 'j' is excluded from this, and is mapped to an 'i'. Next we create the reverse of this to give us the ciphertext alphabet:
ZYXWVUSQPNLKJHGFDACRTEMOIB
We then get the mapping of:
BIOMETRCADFGHJKLNPQSUVWXYZ ZYXWVUSQPNLKJHGFDACRTEMOIB
Now we take an "f" and which will map to "l", "o" to "x", and so on. We then get the ciphertext of:
LXSVJVPN
The basic coding in C# is:
public static string ArrayReverseString(string stringToReverse) { var charArray = stringToReverse.ToCharArray(); Array.Reverse(charArray); return new string(charArray); } public static (string, string) wolseley(string word, string secret) { string alphabet = "abcdefghijklmnopqrstuvwxyz"; string grid = ""; string cipher = ""; string gridreverse = ""; foreach (char ch in secret) { if (!grid.Contains(ch)) { grid = grid + ch; } } foreach (char ch in alphabet) { if (!grid.Contains(ch)) { grid = grid + ch; } } gridreverse = ArrayReverseString(grid); word = word.Replace("j", "i"); foreach (char ch in word) { var pos = grid.IndexOf(ch); if (pos >= 0) cipher = cipher + gridreverse[pos]; else cipher = cipher + ch; } return (cipher.ToUpper(), grid); }