-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcypher.js
107 lines (81 loc) · 2.29 KB
/
cypher.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
var currentSpin = 0;
var outterCode = [
"a", "c", "4", "h", "e", "f", "g","d", "i", "u","8",
"b", "m", "n", "3", "9", "q", "s", "r","w",
"5", "o", "7", "6", "y", "z"
]
var innerCode = [
"r", "g", "x", "f", "n", "q", "m", "b", "u", "h", "v", "o",
"a", "c", "w", "e", "p", "i", "j", "t", "d", "s", "k", "x", "y", "l"
]
innerCode = innerCode.map(element => {
return element.toUpperCase();
});
outterCode = outterCode.map(element => {
return element.toUpperCase();
});
var spinLeft = function() {
currentSpin+=1;
outterCode.unshift(outterCode.pop())
spinny();
}
var spinRight = function() {
currentSpin-=1;
outterCode.push(outterCode.shift())
spinny();
}
var spinny = function() {
var img = document.getElementById('outterring');
if (currentSpin > 25) {
currentSpin = 0;
}
if (currentSpin < 0) {
currentSpin = 25;
}
var degs = (currentSpin * (360/26));
img.style.transform = 'rotate(' + degs + 'deg)';
parseThing();
}
var myInput = document.getElementById("input");
var theOutput = document.getElementById("output");
var doNotOmit = document.getElementById("donotomit");
var replaceUnknown = document.getElementById("replaceunknown");
var encodeMode = document.getElementById("encode");
var parseThing = function() {
var code = myInput.value;
var codeArray = code.split("");
var fromCode;
var toCode;
if(encodeMode.checked == true) {
fromCode = innerCode;
toCode = outterCode;
}
else {
fromCode = outterCode;
toCode = innerCode;
}
var output = [];
for (v=0; v<codeArray.length; v++) {
var letter = codeArray[v];
var letterPosition = fromCode.findIndex((code) => code === letter);
if(letterPosition == -1 && doNotOmit.checked == true) {
if (replaceUnknown.checked == true) {
output.push("?");
}
else {
output.push(letter);
}
}
else {
output.push(toCode[letterPosition]);
}
}
var result = output.join('')
console.log(result);
theOutput.value = result;
}
myInput.onkeyup = function(e) {
e = e || window.event;
myInput.value = myInput.value.toUpperCase()
parseThing();
};