Write a program called crypto.js that encrypts passwords containing uppercase/lo
ID: 3572027 • 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
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
<!DOCTYPE html>
<html>
<body>
<h3><p>This program will encrypt user passwords.</p></h3>
<!--uncomment this if you want user to enter the password
<button>Try it</button>-->
<h3><p id="password"></p></h3>
<h3><p id="encrypt"></p></h3>
<h3><p id="demo"></p></h3>
<script>
window.myFunction(); //comment this for making password user driven
function myFunction() {
var t="",x="",i,pass="";
/*uncomment this if you want user to enter the password
var foo = prompt("Give me a password");*/
var foo="Pizza2Day!"; //comment this for making password user driven
pass=pass+"Password: "+foo;
t=t+"Encrypting ……………";
document.getElementById("password").innerHTML = pass;
document.getElementById("encrypt").innerHTML = t;
var map = new Object();
map["a"] = "m";
map["b"] = "h";
map["c"] = "t";
map["d"] = "f";
map["e"] = "g";
map["f"] = "k";
map["g"] = "b";
map["h"] = "p";
map["i"] = "j";
map["j"] = "w";
map["k"] = "e";
map["l"] = "r";
map["m"] = "q";
map["n"] = "s";
map["o"] = "l";
map["p"] = "n";
map["q"] = "i";
map["r"] = "u";
map["s"] = "o";
map["t"] = "x";
map["u"] = "z";
map["v"] = "y";
map["w"] = "v";
map["x"] = "d";
map["y"] = "c";
map["z"] = "a";
function get(k) {
return map[k];
}
for (i=0; i<foo.length; i++) {
if(foo.charCodeAt(i)>=97 && foo.charCodeAt(i)<=122){
x = x +get(foo.charAt(i));
}
else if(foo.charCodeAt(i)>=65 && foo.charCodeAt(i)<=90){
x = x +get(foo.charAt(i).toLowerCase()).toUpperCase();
}
else
{
x=x+foo.charAt(i);
}
}
x="Encrypted Password: "+x
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.