Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fix the following program so that it works and it prints the encrypted message p

ID: 3753722 • Letter: F

Question

Fix the following program so that it works and it prints the encrypted message provided on the command line. REQUIREMENT: The program must run with –use-strict directive: >> node --use-strict cipher.js HELLO

function encrypt(str) { Plain = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''); Cipher = "XYZABCDEFGHIJKLMNOPQRSTUVW".split(''); for (var i = 0; i < str.length; i ++) { index = Plain.indexOf(str[i]) str[i] = Cipher[index]; } } const wordinput = process.argv[2]; encrypt(wordinput) console.log(wordinput);

Explanation / Answer

If you have any doubts, please give me comment...

"use strict";

function encrypt(str) {

Plain = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');

Cipher = "XYZABCDEFGHIJKLMNOPQRSTUVW".split('');

var new_str = "";

for (var i = 0; i < str.length; i++) {

index = Plain.indexOf(str[i].toUpperCase());

if(index!=-1)

new_str += Cipher[index];

else

new_str += str[i];

}

return new_str;

}

const wordinput = process.argv[2];

console.log(encrypt(wordinput));