Write a program called crypto.js that encrypts passwords containing uppercase/lo
ID: 3803403 • Letter: W
Question
Write a 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 approach.
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
function crypto() {
var pass = "Pizza2Day!";
var flag = 0;
var encryptPass="";
var originalValues = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
var encryptedValues = ['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(var i=0; i < pass.length; i++) {
flag = 0;
for(var j = 0; j < originalValues.length ; j++){
if(originalValues[j] == pass.charAt(i)){
encryptPass = encryptPass + encryptedValues[j];
flag = 1;
break;
}
else if(originalValues[j].toUpperCase() == pass.charAt(i)){
encryptPass = encryptPass + encryptedValues[j].toUpperCase();
flag = 1;
break;
}
}
if(flag == 0){
encryptPass = encryptPass + pass.charAt(i);
}
}
alert("New Password : "+encryptPass);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.