Write a Java Script program called crypto.js that encrypts passwords containing
ID: 3740877 • Letter: W
Question
Write a Java Script program called crypto.js that encrypts passwords containing uppercase/lowercase characters, digits, and special characters. Use Pizza2Day! For the password.
See Sample Execution Below:
This program will encrypt user passwords.
Password: Pizza2Day!
Encrypting ……………
Encrypted Password: Njaam2Fmc!
The encryption key to use is below:
Original Value
Encrypted Value
a
m
b
h
c
t
d
f
e
g
f
k
g
b
h
p
i
j
j
w
k
e
l
r
m
q
n
s
o
l
p
n
q
i
r
u
s
o
t
x
u
z
v
y
w
v
x
d
y
c
z
a
Hint: Think how you could represent the encrypted value with an array and the decrypted value as the index position of the array. A dictionary would be a better approac
Original Value
Encrypted Value
a
m
b
h
c
t
d
f
e
g
f
k
g
b
h
p
i
j
j
w
k
e
l
r
m
q
n
s
o
l
p
n
q
i
r
u
s
o
t
x
u
z
v
y
w
v
x
d
y
c
z
a
Explanation / Answer
If you have any doubts, please give me comment...
str = "Pizza2Day!";
enc = encrypt(str);
console.log(enc);
function encrypt(str){
enc_str = "";
enc_values = ['m', 'h', 't', 'f', 'g','k', 'b','p', 'j', 'w', 'e', 'r', 'q', 's', 'l', 'n', 'i', 'u', 'o', 'x', 'z', 'y', 'v', 'd', 'c', 'a'];
for(i=0; i<str.length; i++){
ascii = str[i].charCodeAt(0);
if(ascii>=65 && ascii<=91)
enc_str += enc_values[ascii-65].toUpperCase();
else if(ascii>=97 && ascii<=122)
enc_str += enc_values[ascii-97];
else
enc_str += str[i];
}
return enc_str;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.