-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
161 lines (139 loc) · 3.72 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Encryption</title>
<style>
:root {
font-size: 10px;
}
* {
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
margin: 0;
background-color: black;
}
body>form {
display: flex;
flex-direction: column;
height: 100vh;
}
h2 {
width: 100%;
font-family: Arial, Helvetica, sans-serif;
cursor: default;
color: lightgray;
font-size: 2.4rem;
line-height: 2.4rem;
padding: 1.2rem;
margin: 0;
text-align: center;
}
textarea {
width: 100%;
margin: 0;
padding: 0.8rem;
flex-grow: 1;
font-size: 1.6rem;
font-family: consolas;
color: lightgray;
outline: none;
border: none;
resize: none;
background-color: transparent;
}
input[type="submit"] {
width: 100%;
padding: 1.2rem;
font-family: Arial, Helvetica, sans-serif;
font-size: 2.4rem;
line-height: 2.4rem;
text-transform: uppercase;
color: gray;
outline: none;
border: none;
cursor: pointer;
background-color: transparent;
transition: color ease-out 0.2s;
}
input[type="submit"]:hover {
color: lightgray;
}
@media screen and (min-width: 1200px) {
body {
flex-direction: row;
height: 100vh;
}
body>form {
flex-grow: 1;
height: 100%;
}
}
</style>
<script>
function encrypt(event) {
event.preventDefault();
const text = document.querySelector('#decrypted')?.value;
if (!text) {
alert('Please, enter the encryption text!');
return;
}
let cursor = 0;
let output = '';
const result = document.querySelector('#encrypted');
const key = prompt('Enter the encryption key:', '');
if (result && key) {
for (let i = 0; i < text.length; i++) {
if (cursor > (key.length - 1)) cursor = 0;
output += text[i].charCodeAt(0) + key[cursor].charCodeAt(0);
if (i != (text.length - 1)) output += ' ';
cursor++;
}
result.value = output;
alert('Done!');
} else {
alert('Please, enter the encryption key!');
}
}
function decrypt(event) {
event.preventDefault();
const text = document.querySelector('#encrypted')?.value.split(' ');
if (!text) {
alert('Please, enter the encrypted text!');
return;
}
let cursor = 0;
let output = '';
const result = document.querySelector('#decrypted');
const key = prompt('Enter the decryption key:', '');
if (result && key) {
for (let i = 0; i < text.length; i++) {
if (cursor > (key.length - 1)) cursor = 0;
output += String.fromCharCode(Math.abs(text[i] - key[cursor].charCodeAt(0)));
cursor++;
}
result.value = output;
alert('Done!');
} else {
alert('Please, enter the decryption key!');
}
}
</script>
</head>
<body>
<form onsubmit="encrypt(event);">
<h2>Decrypted</h2>
<textarea id="decrypted" placeholder="Some text..."></textarea>
<input type="submit" value="Encrypt" />
</form>
<form onsubmit="decrypt(event);">
<h2>Encrypted</h2>
<textarea id="encrypted" placeholder="97 18 44..."></textarea>
<input type="submit" value="Decrypt" />
</form>
</body>
</html>