uY,qROHhWVSDqPtqhTEroLI.gPtspMJygDfGDzdEvWTJ lOzkKFyZOLwbTxXU,mjVzWyZXUcSPIiXUxcQGBA cHsiMHGDdNqngKygOJG kZzjOEeSNLIbFzonkaEifVJxaIwWRHlaX fFCeP,rWzaOLnRrbEmW,.yWNDAhEzeOurcMxspPxmLzrSGkKHzmdArSPIpQucRQNzkcHuXUNncZzwkH eFwtfCkUzqYVHyjImbQO
×
Components of the cipher:
1) The plaintext alphabet. It defines, what characters can be used in encoding of a message.
2) The cipher alphabet. This will be clarified in the example.
3) The original message. It must contain only the characters from the plaintext alphabet.
4) The encoded message. It too, must contain only the characters from the plaintext alphabet.
Contest's message was encoded using alphabet "
ABC...XYZabc...xyz .,"
(uppercase letters + lowercase letters + punctuation). Note the space between lowercase z and the period.
The example, used in explanation
For the sake of simplicity, I will use the following example throughout all my explanations:
Plaintext alphabet: "
ABCDEFG"
Original message: "
FBCDA"
This message is encoded to "
BCEAA"
.
Encoding and decoding explained
Encoding procedure is very simple:
1) Produce the initial state of the cipher alphabet. Take the plaintext alphabet, split it in half (if its size is odd, make sure the left side is the smaller one), swap these two portions together and join it again.
Example: "
ABCDEFG"
->
"
ABC"
, "
DEFG"
->
"
DEFGABC"
2) Take the first character from the original string and find its position in the plaintext alphabet.
Example: "
F"
is the 6th character in the plaintext alphabet.
3) Substitute this character with the character in the cipher alphabet, whose position you have found in the previous step.
Example: "
F"
becomes "
B"
, because "
B"
is 6th in the cipher alphabet.
4) Split the cipher alphabet at the character you have just used, swap the two portions and join them again.
Example: "
DEFGABC"
->
"
DEFGA"
, "
BC"
->
"
BCDEFGA"
5) If the original string isn't fully encoded yet, move on to the next character and go to step 2 with the new cipher alphabet.
The example is encoded like this:
ABCDEFG -> ABCDEFG -> ABCDEFG -> ABCDEFG -> ABCDEFG
DEFGABC -> BCDEFGA -> CDEFGAB -> EFGABCD -> ABCDEFG
[B] [C] [E] [A] [A]
To decode the message you should follow exactly the same procedure as above, except you should substitute original message with the encoded message (and vice-versa) and in steps 2 and 3 subsitute plaintext alphabet with the cipher alphabet (and vice-versa).
Encoding a message with pen and paper
It is far simpler to maintain the cipher alphabet as an offset from the plaintext alphabet. I.e. the amount of characters you should move to the right, in order to get a corresponding letter from the cipher alphabet. So, here is a way to encode a message using offsets:
First, write the alphabet and number all the letters in order, starting with a zero. This way 'A' becomes 0, 'B' becomes 1 etc. Now, take the length of the alphabet and divide it by 2 (drop the remainder, if any). This will be the initial offset.
Now, take the first character of the message and find it in the alphabet you wrote down before. Add its number to the offset and calculate the sum modulo alphabet's length. The result is the offset for the next letter in the message AND it corresponds to the first character in the encoded string. Repeat this until you encode the entire message.
The example string is encoded like so:
A B C D E F G Initial offset is 7 / 2 = 3.
0 1 2 3 4 5 6 Length of the alphabet is 7.
Original | | | Enc.
char (pos) | Offset | New offset | char
-----------+--------+-----------------+------
F (5) | 3 | (3 + 5) % 7 = 1 | B
B (1) | 1 | (1 + 1) % 7 = 2 | C
C (2) | 2 | (2 + 2) % 7 = 4 | E
D (3) | 4 | (4 + 3) % 7 = 0 | A
A (0) | 0 | (0 + 0) % 7 = 0 | A
Decoding a message with pen and paper
As with encoding, write the alphabet and number all the letters in order, starting with a zero. Find the initial offset by diving length of the alphabet by two and dropping the remainder.
Now take the first character of the encoded string and find its numeric value in the alphabet. Add alphabet's length to it and subtract current offset. This value modulo alphabet's length will correspond to the first letter in the original message. The offset for the next letter equals the numeric value of the current encoded letter. Repeat this for other characters in the message until you decode it all.
Decoding the example goes like this:
A B C D E F G Initial offset is 7 / 2 = 3.
0 1 2 3 4 5 6 Length of the alphabet is 7.
Encoded | | | Orig
char (pos) | Offset | Original char pos | char
-----------+--------+---------------------+-----
B (1) | 3 | (1 + 7 - 3) % 7 = 5 | F
C (2) | 1 | (2 + 7 - 1) % 7 = 1 | B
E (4) | 2 | (4 + 7 - 2) % 7 = 2 | C
A (0) | 4 | (0 + 7 - 4) % 7 = 3 | D
A (0) | 0 | (0 + 7 - 0) % 7 = 0 | A
And now you know.