Encryption/Decryption of Enigma Machine


#22

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 ?


#23

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


#24

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)


#25

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


#26

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"


#27

Thank you very much :slight_smile:


#28

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


#29

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.