[Community Puzzle] Encryption/Decryption of Enigma Machine

Hi, Everyone.
Same issue here, for me I always fail validators 4 and 6, it’s probably something very stupid , but i can’t find it.
I check if the N number is < 50 , i check if message in a regexp are in [A-Z],. I don’t really understand what some mean by the original size message , i should only write the 50 first chars ?

Hi, if someone else has this issue, just use a custom test case with a very long message.

just beware of borders (values < or > to the 26 chars when converting)
beware to negatives values
beware to end of lines (fgets default on some tests)

can you please eleborate? I cant decode it even manually.

To be simple for the encoding with the word "ABCD" :


Step 1: apply CAESAR with the incrementing number (let’s say 4 here)

"A" + (4+0) = "E"
"B" + (4+1) = "G"
"C" + (4+2) = "I" 
"D" + (4+3) = "K"

"ABCD" becomes "EGIK"

Step 2 : translate trough first rotor (let’s say "BDFHJLCPRTXVZNYEIWGAKMUSQO" here)

FROM | 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
               ↓   ↓   ↓   ↓
TO   | B D F H J L C P R T X V Z N Y E I W G A K M U S Q O

"EGIK" becomes "JCRX"

Step 3 : translate trough second rotor (let’s say "AJDKSIRUXBLHWTMCQGZNPYFVOE" here)

FROM | 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
           ↓             ↓               ↓           ↓
TO   | A J D K S I R U X B L H W T M C Q G Z N P Y F V O E

"JCRX" becomes "BDGV"

Step 4 : translate trough third rotor (let’s say "EKMFLGDQVZNTOWYHXUSPAIBRCJ" here)

FROM | 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
         ↓   ↓     ↓                             ↓
TO   | E K M F L G D Q V Z N T O W Y H X U S P A I B R C J

"BDGV" becomes"KFDI"

So after those 4 steps "ABCD" is encrypted to "KFDI"


To do decryption of “KFDI” :

Step 1 : translate from third rotor (let’s say "EKMFLGDQVZNTOWYHXUSPAIBRCJ" here)

FROM | E K M F L G D Q V Z N T O W Y H X U S P A I B R C J
         ↓   ↓     ↓                             ↓
TO   | 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

"KFDI" becomes"BDGV"

Step 2 : translate from second rotor (let’s say "AJDKSIRUXBLHWTMCQGZNPYFVOE" here)

FROM | A J D K S I R U X B L H W T M C Q G Z N P Y F V O E
           ↓             ↓               ↓           ↓
TO   | 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

"BDGV" becomes "JCRX"

Step 3 : translate from first rotor (let’s say "BDFHJLCPRTXVZNYEIWGAKMUSQO" here)

FROM | B D F H J L C P R T X V Z N Y E I W G A K M U S Q O
               ↓   ↓   ↓   ↓
TO   | 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

"JCRX" becomes "EGIK"

Step 4: undo CAESAR with the incrementing number (let’s say 4 here)

"E" - (4+0) = "A"
"G" - (4+1) = "B"
"I" - (4+2) = "C" 
"K" - (4+3) = "D"

"EGIK" becomes "ABCD"

So after those 4 steps "KFDI" is decrypted to "ABCD"

10 Likes

Thank you very much :slight_smile:

Same sh*t, could I get test cases for 4, 6 tests?

Considering the number of people facing an issue with this puzzle (+ lots of these issues seem to come from the fact that tests are shorter than validators, in particular <26 the size of the alphabet), I added two hopefully helpful testcases.

2 Likes

Thank you, this explanation of is a lot clearer than the one included in the exercise.

Hi,
I passed all the tests for the Enigma Encryption/Decryption, but once submitted validators 1 and 2 fails.

I don’t understand why !
What are differences between validator test and ide test ?
In my code i have no hard-coded values, all contraints are implemented.
Can i have the test game of validator 1 and 2 to fixe my issue ?

Hi Sudeep,

All the test cases work but when I click on submit, I only have 66%. The test cases 4 and 5 do not work and I frankly have no idea why.
My test case for the decoding is the following :
(((int)message4.charAt(i))-pseudoRandomNumber-i-65)%26+65<65

1 Like

Thank you very much, was very helpful! :slightly_smiling_face:

Hi,
Same for me here, I’d like to be able to see validators 1 and 2 to understand what I’m doing the wrong way!
Thanks,

Hello,

There is a problem with the starter code (aka auto generated code) for C, it does not read in the input properly.
The line:
fgets(rotor, 27, stdin);
it should be
fgets(rotor, 27, stdin); fgetc(stdin);

Can this be corrected?

@The_Auditor Ok so you posted this issue at 3 places at the same time. It’s fixed (and I’ve answered somewhere else).

@Niako thanks for correction. Sorry for multiple posts, was not sure which of the 3 locations was the right one. Will be more patient in the future.

Hey!
I have a problem, I can’t pass the validator n°3
I don’t exactly understand why as some of you seems to have problems on validators 4 and 6, I guess it’s a special exception in the validator 3 that’s not in every other codes.
Could someone help me in DM or on Discord ? Thanks in advance !
(PS : My Discord is Thomas “Sigeth” S.#9015 if you want to DM me, I’m on the official CodinGame server)

I’ll share it here, it’s simpler for everyone:

Validator 3:
Input:

DECODE
8
BDFHJLCPRTXVZNYEIWGAKMUSQO
UXBLHWTMCQGZNPYFVOEAJDKSIR
EKMFLGNTOWYHXUSPAIBRCJDQVZ
EPXAMAGWGUWQSTPTYPOCMYYJPGUEWCVGGCEZKANOQ

Output:

BETTERTHREEHOURSTOOSOONTHANAMINUTETOOLATE

Good luck!

1 Like

Ok I understood why.

To describe my problem, I understood the statement “If the second ROTOR is AJDKSIRUXBLHWTMCQGZNPYFVOE” as a condition that we needed to check out in our code.
Well, thanks for giving me the validator !

Hello,

Just have passed all test but im having 66% at the end, whats the problem?

im using C++.

Thanks in advance.