Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rosettaStone(input) {
- const templateRows = Number(input.shift());
- const templateMatrix = [];
- for (let i = 0; i < templateRows; i++) {
- let currentRow = input.shift().split(' ');
- currentRow = currentRow.map(Number)
- templateMatrix.push(currentRow);
- }
- const encodedMatrix = input.map((row) => row.split(' ').map((x) => Number(x)));
- const letterDecipher = letterCipher => {
- let num = letterCipher;
- if (letterCipher >= 27) {
- num = letterCipher % 27;
- }
- let letter = ' ';
- if (num > 0) {
- letter = String.fromCharCode(num + 64);
- }
- return letter
- }
- let message = '';
- for (let row = 0; row < encodedMatrix.length; row++) {
- for (let col = 0; col < encodedMatrix[0].length; col++) {
- let codeCipher = encodedMatrix[row][col];
- let codeDecipher = templateMatrix[row % templateRows][col % templateMatrix[0].length];
- let currentLetterCode = codeCipher + codeDecipher;
- message += letterDecipher(currentLetterCode);
- }
- }
- console.log(message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement