Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function imitationGame(input) {
- let textToDecode = input.shift();
- let actions = {
- 'ChangeAll': changeall,
- 'Move': move,
- 'Insert': insertletter,
- };
- while (input[0] !== "Decode") {
- let line = input.shift();
- let [command, param1, param2] = line.split("|");
- let action = actions[command];
- action(param1, param2);
- }
- console.log(`The decrypted message is: ${textToDecode}`);
- function changeall(param1, param2) {
- while(textToDecode.includes(param1)){
- textToDecode = textToDecode.replace(param1, param2);
- }
- }
- function move(n,param2){
- n = Number(n);
- let left= textToDecode.substring(0,n);
- let right = textToDecode.substring(n);
- textToDecode = right+ left;
- }
- function insertletter(param1,param2){
- param1 = Number(param1);
- let left = textToDecode.substring(0,param1);
- let right = textToDecode.substring(param1);
- textToDecode = left + param2 + right;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment