-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
92 lines (77 loc) · 3.34 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const text = document.querySelector("#textmsg")
const password = document.querySelector('#password')
const result = document.querySelector("#result")
var clutter = "";
var parinam = "";
function encryption() {
document.querySelector("#encrypt-btn").addEventListener("click", function () {
var pass = document.getElementById("password").value;
var input = document.getElementById("textmsg").value;
var str = input.split("")
str.forEach(element => {
clutter += `€${(element.charCodeAt())} `
});
document.querySelector("#result").innerHTML = clutter
var dataarr = [];
if(JSON.parse(localStorage.getItem('data1'))){
dataarr = JSON.parse(localStorage.getItem('data1'));
dataarr.push({"pass":pass, "input":input, "clutter":clutter})
}else{
dataarr = [{"pass":pass,"input":input,"clutter":clutter}]
}
localStorage.setItem(`data1`, JSON.stringify(dataarr))
})
}
function decryption() {
document.querySelector("#decrypt-btn").addEventListener("click", function () {
var clutter2 = '';
var input2 = document.querySelector("#emojimsg").value
var finalPass = document.querySelector("#finalpassword").value
var user = JSON.parse(localStorage.getItem('data1'))
console.log(user)
var str2 = input2.split(" ")
str2.forEach(element => {
clutter2 += `&#${(element.codePointAt(0))} `
});
var found;
for(let i of user){
if(i.clutter == clutter2){
found = i;
}
}
if (found.clutter === clutter2) {
console.log("jay ho")
document.querySelector("#result").style.display = `block`
document.querySelector("#result").style.color = `#eee`
document.querySelector("#result").innerHTML = found.input
} else {
document.querySelector("#result").style.display = `block`
document.querySelector("#result").style.color = `red`
document.querySelector("#result").innerHTML = "Wrong password!"
}
})
}
function btnClicking() {
document.querySelector("button").addEventListener("click", function () {
document.querySelector("#result").style.display = "block"
})
document.querySelector("#dec-btn").addEventListener("click", function () {
document.querySelector("#result").style.display = "none"
document.querySelector("#decryption").style.display = "block"
document.querySelector("#encryption").style.display = "none"
document.querySelector("#dec-btn").style.backgroundColor = "#333"
document.querySelector("#enc-btn").style.backgroundColor = "#222"
document.querySelector("#main>h1 span").style.rotate = '270deg'
})
document.querySelector("#enc-btn").addEventListener("click", function () {
document.querySelector("#decryption").style.display = "none"
document.querySelector("#result").style.display = "none"
document.querySelector("#encryption").style.display = "block"
document.querySelector("#dec-btn").style.backgroundColor = "#222"
document.querySelector("#enc-btn").style.backgroundColor = "#333"
document.querySelector("#main>h1 span").style.rotate = '90deg'
})
}
encryption();
decryption()
btnClicking();