Advertisement
Spocoman

01. The Imitation Game

Nov 13th, 2023
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function theImitacionGame(input) {
  2.     let message = input.shift();
  3.  
  4.     while (input[0] != "Decode") {
  5.         let tokens = input.shift().split('|');
  6.         let command = tokens[0];
  7.         if (command == "Move") {
  8.             let index = Number(tokens[1]);
  9.             message = message.substring(index) + message.slice(0, index);
  10.         } else if (command == "Insert") {
  11.             let index = Number(tokens[1]);
  12.             let value = tokens[2];
  13.             message = message.slice(0, index) + value + message.slice(index);
  14.         } else if (command == "ChangeAll") {
  15.             let oldStr = tokens[1];
  16.             let newStr = tokens[2];
  17.             while(message.includes(oldStr)){
  18.                 message = message.replace(oldStr, newStr);
  19.             }
  20.         }
  21.     }
  22.  
  23.     console.log(`The decrypted message is: ${message}`);
  24.     return;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement