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));
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.