-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
63 lines (57 loc) · 2.34 KB
/
main.js
File metadata and controls
63 lines (57 loc) · 2.34 KB
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
function encryptROT13() {
const alphabeticalColumn = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', // First Column
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' // Second Column
];
const perAlphabeticalColumn = 26 / 2;
const numericColumn = [
'0', '1', '2', '3', '4', // First Column
'5', '6', '7', '8', '9' // Second Column
];
const perNumericColumn = 10 / 2;
let output = [];
let input = this.value;
let words = input.toUpperCase();
for (let i = 0; i < words.length; i++) {
let result = words.charAt(i);
if (result.match(/[A-Z]/) || result.match(' ')) {
if (result == ' ') {
output.push(" ");
} else if (alphabeticalColumn.indexOf(result) <= 12) {
let index = alphabeticalColumn.indexOf(result);
output.push(alphabeticalColumn[index + perAlphabeticalColumn]);
} else if (alphabeticalColumn.indexOf(result) >= 13 && alphabeticalColumn.indexOf(result) <= 25) {
let index = alphabeticalColumn.indexOf(result);
output.push(alphabeticalColumn[index - perAlphabeticalColumn]);
} else {
document.getElementById('decryptBox').value = 'Invalid Input';
}
} else if (result.match(/[0-9]/)) {
if (numericColumn.indexOf(result) <= 4) {
let index = numericColumn.indexOf(result);
output.push(numericColumn[index + perNumericColumn]);
} else if (numericColumn.indexOf(result) >= 5 && numericColumn.indexOf(result) <= 9) {
let index = numericColumn.indexOf(result);
output.push(numericColumn[index - perNumericColumn]);
} else {
document.getElementById('decryptBox').value = 'Invalid Input';
}
} else if (result.isEmpty() && result.length == 0){
document.getElementById('decryptBox').value = '';
}
}
document.getElementById('decryptBox').value = output.join('');
}
function copyToClipboard() {
let copyText = document.getElementById('decryptBox');
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
alert('Copied to Clipboard!');
copyText.setSelectionRange(0, 0);
copyText.select() = false;
}
function link(){
location.target = "_blank";
location.href = this.href;
}