Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I have already followed you. I would appreciate it if you would try again. Thank you very much.
This Enigma machine is a real nightmare! :-D
Here is my thoughts to understand how the reflector works, especially when changing the start position.
Easy part : the initial mapping, with string given as
STR = A Y B R C U D H E Q F S G L I P J X K N M O T Z V W
this gives the following input/output pairs:
IN = 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
OUT = Y R U H Q S L D Q X N G O K M I E B F Z C W V J A T
In start position A, A is wired to Y, B is wired to R and so on... Now in start position N, what happens?
Whole input alphabet is shifted so that A becomes N. First I would think "N is wired to Y", "O is wired to R"... following this logic, "well, easy, just shift by 13..."
spoler: that does not work at all:
IN = N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
OUT = Y R U H Q S L D Q X N G O K M I E B F Z C W V J A T
the 4 first columns are good, we are safe. N>Y, O>R, P>U, Q>H ... but R>Q is not good, and the whole logic of "pairs of letters" blows out.
Other way of thinking (and IMHO this is the good one): it's the "length" of the wire which remains the same when shifting. Left part of image found in https://brej.org/enigma/Image10.gif made me realize this... The reflector wiring has to be seen as a kind of "comb", meaning the "distance between wire input and output" remains the same.
"Wire length" from A to Y (first pair) is 24 ; A (letter 1 of alphabet) + 24 = letter 25 in alphabet = Y)
Hence...
INPUT = 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
OUTPUT = Y R U H Q S L D Q X N G O K M I E B F Z C W V J A T
LENGTH =24 16 18 04 12 13 05 04 07 14 03 05 02 03 02 07 12 16 13 06 18 01 01 14 24 06
Length is computed as "input + Length = output" in terms of letters (A + 24 letters = Y)
Then if the input is shifted by 1, the output changes based on the same difference in letters from input to output.
INPUT = 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 A
OUTPUT = Z S V I R T M E Q Y O H P L N J F C G A D X W K B U
LENGTH =24 16 18 04 12 13 05 04 07 14 03 05 02 03 02 07 12 16 13 06 18 01 01 14 24 06
Pairs still are pairs (A<=>U, B<=>Z, C<=>S and so on...)
if the shift is 13 (A to N) as in the example:
INPUT = N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
OUTPUT = L E H U D F Y Q C K A T B X Z V R O S M P J I W N G
LENGTH =24 16 18 04 12 13 05 04 07 14 03 05 02 03 02 07 12 16 13 06 18 01 01 14 24 06
Pairs still are pairs (A<=>X, B<=>Z, C<=>V and so on...)
That should help those who did not know how the reflector worked (as I do/did!)
Hi!
I would be OK to approve your translation... If I could! Should you follow me to make this happen? Not sure how to do it, I am new in Codewars translations.
TC.
Two information which may help other codewarriors, which are missing (or I could not deduce it from the kata details) from the details of this kata (for those who, like me, did not know how the Enigma machine works):
1- The "Dot" letter has an influence on the notch. As a matter of fact, the dot letter leads to an offset between the notch and the visible position in the window.
Example:
If notch is "Q" and dot letter is "A", then the notch causes rotation when "Q" is displayed in the window. No change, Dot is in initial position.
If notch is "Q" and dot letter is "Z", then the notch causes rotation when "P" is displayed in the window, because Z has an offset of 25 towards A (0 position) => Q + offset of 25 gives "P".
If notch is "Q" and dot letter is "M", then the notch causes rotation when "C" is displayed in the window, because M has an offset of 12 towards A (0 position) => Q + offset of 12 gives "C".
2- When kata says "While in the actual usage of the original Enigma Machine, punctuation was encoded as words transmitted in the stream, in your code any input character that is not in the range A-Z should be returned unchanged and should not affect the internal state of the machine.", the "A-Z" is to be case-sensitive understood.
That is "A-Z" will be ciphered and crypted, punctuation will leaves the machine status as is (no rotation, no ciphering) ... but range "a-z" will ALSO remains untouched.
Hi! Really helpfull, thank you!
Another piece of information which was missing (or I could not deduce it from the kata details): the "Dot" letter has an influence on the notch. As a matter of fact, the dot letter leads to an offset between the notch and the visible position in the window.
If notch is "Q" and dot letter is "A", then the notch causes rotation when "Q" is diplayed in the window.
If notch is "Q" and dot letter is "Z", then the notch causes rotation when "P" is diplayed in the window, because Z has an offset of 25 towards A (0 position) => Q + offset of 25 gives "P".
If notch is "Q" and dot letter is "M", then the notch causes rotation when "C" is diplayed in the window, because N has an offset of 12 towards A (0 position) => Q + offset of 12 gives "C"
Could the possible inputs be described more in details, especially regarding punctuation?
Is punction always single? Is punctuation always preceeded by a space?
Is "Once upon a time, in a country far far away..." considered as a valid input?
Or would inputs always be like "Once upon a time , in a country far far away . . ." ? (each punctation mark being preceeded by a space)
Suggestion:
@MMMAAANNN's comment was VERY helpful!
but why is part #1 available in 100 languages, and part 2 / 3 / 4 available in Python only? :-(
I cannot check my solution in C# for this part #2.
geezz.... thx for you comment! helped me solve the same issue. even 6 years after it was publish, your comment still has good value (at least to me!)