Cipher CTF Challenge Generator (Solitaire Cipher)Press the blue button to regenerate a Solitaire cipher challenge. With the Solitaire cipher, we shuffle a pack of 52 cards and use the values of these to add to the value of the character. |
Method
With a card shuffle of {10 42 5 48 11 12 38 6 21 40 34 18 13 52 39 32 28 50 22 30 27 41 46 31 37 43 36 29 2 16 3 26 35 49 51 25 8 17 7 20 15 14 23 9 19 24 47 44 45 1 4 33}, then we have 10 for the first card and map 'a' to 'k' (0+10=10). We then have 42 for the second card, and where 'p' is represented by 15, and so we get get 57. We now take 57 (mod 26), we get 5, and which is 'f'. In Python, 57 (mod 26) is simply 57 % 26. The result is:
Plaintext: a p p l e c o r e 0 15 15 11 4 2 14 17 4 Card: 10 42 5 48 11 12 38 6 21 ------------------------------------- 10 57 20 59 15 14 52 23 25 (mod 26) 10 5 20 7 15 14 0 23 25 k f u h p o a x z
The mapping is:
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
To define a value on the cards for the cipher, we could use:
- Clubs: Ace, 2,... 10, J, Q, K becomes to 1, 2, ... 10, 11, 12, 13.
- Diamonds: Ace, 2, ... ,10, J, Q, K becomes 14, 15, ... 23, 24, 25, 26.
- Hearts: Ace, 2, ... 10, J, Q, K becomes 27, 28, ... 36, 37, 38, 39.
- Spades: Ace, 2, ... 10, J, Q, K becomes 40, 41, ...49, 50, 51, 52.
The basic coding in C# is:
public static (string,string) getSolitaire(string s) { s = s.ToLower(); string rtn = ""; var count = 0; int[] cards = new int[52]; for (int i = 0; i < cards.Length; i++) cards[i] =i + 1; shuffle(cards); var str = ""; for (int i = 0; i < cards.Length; i++) str = str+ cards[i] + " "; foreach (char ch in s) { try { if (ch == ' ') rtn = rtn + " "; else if (ch >= 'a' && ch <= 'z') { rtn = rtn + (char) (((Convert.ToInt32(cards[count]) + (int)ch - (int)'a') % 26)+(int)'a'); count++; } } catch (Exception ex) { } } return (rtn,"{"+str.Trim()+"}"); }