[Community Puzzle] Encryption/Decryption of Enigma Machine

Did you read through all the posts here? You may find some hints relevant to you.

1 Like

It is something weird, I have read the whole thread, even so I cannot identify the error, the validators of case 4 and 5 fail me, when other similar validators are passing.

edit: have iddentified the problem, was the size of the string for those two cases.

Hi, Can i have the datas of the Validator 2.
I am passing all the tests and validators but this one not.

I’m using javascript

Hi, I have the same problem that aisak7, I have passed all tests but I’m having 66% after submitting because case 4 and 5 fail… I can’t find the issue, I think I respect all the constraints so would it be possible to get the values from the other tests to understand what happens ?
I’m using java.
Thanks

Do the previous answers here help you?

I’ve read all the thread, and I probably misunderstood some messages but aisak7 was the one who seemed the closest of my problem but I can’t tell… I’ve tried to change my code but it didn’t have any effect on the post-tests

Maybe some suggestions above will help you even though their original questions aren’t the same as yours? If not, then you can always test your code using some custom cases. Probably a good idea to test the whole alphabet.

Initially, I thought the problem was the length of the message but I checked and it seems ok (maybe I’m doing it the wrong way ?Idk), I’ve tested with a custom message with lowercase letter (the whole alphabet) and longer than 50 characters, I’m running out of ideas ^^

Did you try custom test cases with different starting shifts too?

After several attempts, I did it !!
It was a specific error due to…length in one line…
Thanks a lot @5DN1L to keep asking me :slight_smile:

2 Likes

Hello,

I’m trying to understand the β€˜caesar’. From the description, I know that if β€˜caesar’ applied to β€œAAA”, it results β€œEFG”

I’m wondering what the result of β€˜caesar’ when applied to β€œXYZ” or β€œZZZ”?

When you reach the end of the alphabet, you go back to the start of the alphabet again. You may refer to the explanation and examples here:
https://en.wikipedia.org/wiki/Caesar_cipher

Hi, I think I found an error in JavaScript because I deduce someone put 1 rotor where it should be the message and 1 of the rotors is the message, I attach images proofs and the code

const operation = readline();

const pseudoRandomNumber = parseInt(readline());

var alphabet = ["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"];

const message = readline();

let myMessage = message.split("");

let newMessage = [];

var splitRotor = [];

var prueba = [];

console.log("Mensaje a desifrar")

console.log(myMessage);

console.log("Numero aleatoreo: " + pseudoRandomNumber);

console.log("Primer Cifrado:");

console.log(newMessage = firstCaesarShift(myMessage, pseudoRandomNumber));

for (let i = 0; i < 3; i++) {

    const rotor = readline();

    splitRotor = rotor.split("");

    switch (operation) {

        case 'ENCODE':

            for (let k = 0; k < newMessage.length; k++) {

                var index = alphabet.indexOf(newMessage[k]);

                if (index < splitRotor.length) {

                    newMessage[k] = splitRotor[index];

                }

            }

            console.log(newMessage);

            break;

        case 'DECODE':

            // do something

            break;

    }

    console.log("Rotor " + (i + 1) + ": " + rotor);

}

function firstCaesarShift(myText = [], number = 0) {

    for (let i = 0; i < myText.length; i++) {

        var index = alphabet.indexOf(myText[i]);

        if (~index) {

            myText[i] = alphabet[((index + number) + i) % alphabet.length];

        }

    }

    return myText;

}

---------------------------------OUTPUT OF THE CODE------------------------------------------`
Standard Output Stream:
Mensaje a desifrar
[
β€˜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’
]
Numero aleatoreo: 4
Primer Cifrado:
[
β€˜F’, β€˜I’, β€˜L’, β€˜O’, β€˜R’, β€˜U’,
β€˜M’, β€˜A’, β€˜D’, β€˜G’, β€˜L’, β€˜K’,
β€˜P’, β€˜E’, β€˜Q’, β€˜X’, β€˜C’, β€˜R’,
β€˜C’, β€˜X’, β€˜I’, β€˜L’, β€˜U’, β€˜T’,
β€˜S’, β€˜R’
]
[
β€˜I’, β€˜X’, β€˜H’, β€˜M’, β€˜G’, β€˜P’,
β€˜W’, β€˜A’, β€˜K’, β€˜R’, β€˜H’, β€˜L’,
β€˜C’, β€˜S’, β€˜Q’, β€˜V’, β€˜D’, β€˜G’,
β€˜D’, β€˜V’, β€˜X’, β€˜H’, β€˜P’, β€˜N’,
β€˜Z’, β€˜G’
]
Rotor 1: AJDKSIRUXBLHWTMCQGZNPYFVOE
[]
[
β€˜V’, β€˜R’, β€˜Q’, β€˜O’, β€˜D’, β€˜H’,
β€˜B’, β€˜E’, β€˜N’, β€˜U’, β€˜Q’, β€˜T’,
β€˜M’, β€˜S’, β€˜X’, β€˜I’, β€˜F’, β€˜D’,
β€˜F’, β€˜I’, β€˜R’, β€˜Q’, β€˜H’, β€˜W’,
β€˜J’, β€˜D’
]
Rotor 2: EKMFLGDQVZNTOWYHXUSPAIBRCJ
[]
[
β€˜V’, β€˜R’, β€˜Q’, β€˜O’, β€˜D’, β€˜H’,
β€˜A’, β€˜E’, β€˜N’, β€˜U’, β€˜Q’, β€˜T’,
β€˜M’, β€˜S’, β€˜X’, β€˜I’, β€˜F’, β€˜D’,
β€˜F’, β€˜I’, β€˜R’, β€˜Q’, β€˜H’, β€˜W’,
β€˜J’, β€˜D’
]
Rotor 3: AAA
[]

Would you format your src and IN/OUT-puts

to make them 
    easier to read?

sure, I just don’t know how to do it, and honestly, i thought nobody would respond haha, but let me figure out how to do it and ill send it to you

Do not send anything to me. Do write in public.
For formatting source codes:
image

1 Like

i tried, seem it looks better now could you see if you can read it easily

I’ve reformatted your code and also moved your posts to the correct thread. Please search for old posts before creating a new topic in the future, thanks.

1 Like

The issue with your code is that you have not read all the inputs properly. Lines 3 to 5 are the rotor strings. The message is in input line 6. You may refer to the Input section of the puzzle statement for more details.

Also, for debugging on CodinGame, you use console.error.
console.log is for outputting the final answer only.

Hope this helps.

Excellent code exercise, thank you for this and it was an interesting project to work on!