[Community Puzzle] Encryption/Decryption of Enigma Machine

I’m working on this puzzle, and when I click the forum link on the left in the puzzle screen it doesn’t take me to this thread. Instead I just get taken to the main forum page. Most puzzles link directly to a post in the forum, so maybe this is a mistake? Just wanted to let people know.

I’m enjoying the puzzle. Took me a minute to realize that if I’m going to decode I need to be going in the reverse order. I’m learning to really think things through before I just go hammering away at the keyboard.

1 Like

Thank you for reporting. I’m keeping a list of puzzles with wrong/missing forum links, and hopefully one day I can ask somebody at CodinGame to fix them all.

Hi There: regarding the mentioned puzzle (Coding Games and Programming Challenges to Code Better) there is something I don’t understand about the rules: AFAIK, I will get the operation to be performed (ENCODE or DECODE), the initial shift, the rotors (first to third) and finally the message.

For ENCODE operation I should pass the message through rotors 1, 2 and 3 with the corresponding shift and so on.

So far so good, but: should DECODE go the inverse way (rotors 3, 2 and 1)? The shift should be the same or it should also be inverted (i.e. substract the shift and substracting 1 for each character as said in the description)?

Also, the starting boilerplate code is not so clear. Leaving questions in the comments:

import ...

class Solution {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String operation = in.nextLine();
        int pseudoRandomNumber = in.nextInt(); // this is the initial shift (4 in the example), right?

        if (in.hasNextLine()) {
            in.nextLine(); // What is this for? It's reading a line without assigning to a variable
        }
        for (int i = 0; i < 3; i++) {
            String rotor = in.nextLine(); // only one variable for all the rotors? what if you need to decode?
        }
        String message = in.nextLine();

        System.out.println("message");
    }
}

Thanks in advance for your comments and clarifications

should DECODE go the inverse way (rotors 3, 2 and 1)?

DECODE means you should find the original message, which, after going through the given ROTOR I, ROTOR II and ROTOR III (in that order) with the given starting shift, will become the message you have to decode.

In other words, if you plug your answer into the code you have written for the ENCODE process, the answer will be encoded and become the same message given to decode.

Inverse way or not or inverted shift or not depends on how you tackle the problem.

this is the initial shift (4 in the example), right?

Right.

What is this for? It’s reading a line without assigning to a variable

This is for reading the newline character after the initial shift.

only one variable for all the rotors? what if you need to decode?

The default code always stops at that. It will be up to you to decide how to handle that variable - whether to process it immediately, or store it somewhere for later processing.

=====
Hope it helps. Feel free to ask again if you have further questions.