-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
108 lines (104 loc) · 2.45 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const cipherMap = {
'a': ':3:3:3',
'b': ':3:3:D',
'c': ':3:3:P',
'd': ':3:3:O',
'e': ':3:D:3',
'f': ':3:D:D',
'g': ':3:D:P',
'h': ':3:D:O',
'i': ':3:P:3',
'j': ':3:P:D',
'k': ':3:P:P',
'l': ':3:P:O',
'm': ':3:O:3',
'n': ':3:O:D',
'o': ':3:O:P',
'p': ':3:O:O',
'q': ':D:3:3',
'r': ':D:3:D',
's': ':D:3:P',
't': ':D:3:O',
'u': ':D:D:3',
'v': ':D:D:D',
'w': ':D:D:P',
'x': ':D:D:O',
'y': ':D:P:3',
'z': ':D:P:D',
' ': ':D:P:P',
'!': ':D:P:O',
'?': ':D:O:3',
',': ':D:O:D',
'.': ':D:O:P',
';': ':D:O:O',
':': ':P:3:3',
"'": ':P:3:D',
'"': ':P:3:P',
'(': ':P:3:O',
')': ':P:D:3',
'[': ':P:D:D',
']': ':P:D:P',
'{': ':P:D:O',
'}': ':P:P:3',
'@': ':P:P:D',
'#': ':P:P:P',
'$': ':P:P:O',
'%': ':P:O:3',
'&': ':P:O:D',
'*': ':P:O:P',
'+': ':P:O:O',
'-': ':O:3:3',
'/': ':O:3:D',
'\\': ':O:3:P',
'=': ':O:3:O',
'<': ':O:D:3',
'>': ':O:D:D',
'^': ':O:D:P',
'~': ':O:D:O',
'0': ':O:P:3',
'1': ':O:P:D',
'2': ':O:P:P',
'3': ':O:P:O',
'4': ':O:O:3',
'5': ':O:O:D',
'6': ':O:O:P',
'7': ':O:O:O',
'8': ':3:3:3:3',
'9': ':D:D:D:D'
};
const decipherMap = {};
for (const key in cipherMap) {
decipherMap[cipherMap[key]] = key;
}
function cypher() {
const inputText = document.getElementById('inputText').value.toLowerCase();
let outputText = '';
for (let i = 0; i < inputText.length; i++) {
outputText += cipherMap[inputText[i]] || inputText[i];
}
document.getElementById('outputText').value = outputText;
}
function decypher() {
const inputText = document.getElementById('inputText').value;
let outputText = '';
const pattern = /(:3|:D|:P|:O)/g;
const chunks = inputText.match(pattern);
if (chunks) {
for (let i = 0; i < chunks.length; i += 3) {
const chunk = chunks.slice(i, i + 3).join('');
outputText += decipherMap[chunk] || 'not defined';
}
}
document.getElementById('outputText').value = outputText;
}
const dialog = document.querySelector('dialog');
const showDialogButton = document.querySelector('#fab');
if (!dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
showDialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('.close').addEventListener('click', function() {
dialog.close();
});