-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.html
160 lines (150 loc) · 5.22 KB
/
decoder.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
<html>
<head>
<script type="text/javascript">
var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.,!?<>"/\\\'';
var key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.,!?<>"/\\\'';
var deg = 360 / key.length;
function shuffle(theString) {
var parts = theString.split('');
for (var i = parts.length; i > 0;) {
var random = parseInt(Math.random() * i);
var temp = parts[--i];
parts[i] = parts[random];
parts[random] = temp;
}
return parts.join('');
}
function encode() {
var cKey = key;
var pt = document.getElementById('plaintext').value;
var ct = '';
for(i=0;i<pt.length;i++) {
// For each character, encode, and then update the key
cc = pt.charAt(i).toUpperCase();
shifts = alpha.indexOf(cc);
if (shifts < 0) {
ct = ct + cc;
} else {
ec = cKey.charAt(shifts);
ct = ct + ec;
cKey = cKey.substring(shifts)+cKey.substring(0,shifts);
}
}
document.getElementById('ciphertext').value = ct;
}
function decode() {
var cKey = key;
var ct = document.getElementById('ciphertext').value;
var pt = '';
for(i=0;i<ct.length;i++) {
// For each character, encode, and then update the key
cc = ct.charAt(i).toUpperCase();
shifts = cKey.indexOf(cc);
if (shifts < 0) {
pt = pt + cc;
} else {
ec = alpha.charAt(shifts);
pt = pt + ec;
cKey = cKey.substring(shifts)+cKey.substring(0,shifts);
}
}
document.getElementById('plaintext').value = pt;
}
function rekey(){
ct = document.getElementById('ciphertext').value;
if(ct){
if(confirm('Are you sure you want to generate your new key? The current encrypted text will become undecryptable!')) key = shuffle(key);
} else {
key = shuffle(key);
}
document.getElementById('key').value = key;
document.getElementById('inner-ring').innerHTML = '';
newHTML = '';
for(i=0;i<key.length;i++) {
newHTML = newHTML + '<a class="inner-ring-letter" style="-moz-transform:rotate('+((i*deg))+'deg);">'+key.charAt(i).toUpperCase()+'</a>';
}
document.getElementById('inner-ring').innerHTML = newHTML;
}
</script>
<style>
#left-container {
float: none;
}
#right-container {
float: none;
}
#ring {
position: relative;
border: solid black 1px;
background-color: transparent;
width: 1160px;
height: 580px;
}
#inner-ring-container, #outer-ring-container {
position: absolute;
top: 10px;
width: 560px;
height: 560px;
color: black;
font-weight: bold;
font-family: "Courier New", Courier, monospace;
}
#inner-ring-container { left: 10px; background: url(img/ir-bg.png) no-repeat center top transparent; }
#outer-ring-container { left: 590px; background: url(img/or-bg.png) no-repeat center top transparent; }
.inner-ring-letter {
position: absolute;
top: 35px;
left: 275px;
transform-origin: 5px 245px;
font-size: 18px;
}
.outer-ring-letter {
position: absolute;
top: 0;
left: 274px;
font-size: 28px;
transform-origin: 7px 280px;
}
</style>
</head>
<body>
<div id="right-container">
<strong>Plaintext:</strong><br/>
<textarea rows=8 cols=80 id="plaintext"></textarea><br/>
<strong>Ciphertext:</strong><br/>
<textarea rows=8 cols=80 id="ciphertext"></textarea><br/>
<strong>Key:</strong><br/>
<input type=text size=50 id="key"/><br/><br/>
<button onclick="encode();">Encode</button>
<button onclick="decode();">Decode</button>
<button onclick="rekey();">Generate New Key</button>
<script type="text/javascript">
document.getElementById('key').value = key;
</script>
</div>
<br/><br/>
<div id="left-container">
<strong>Printable Version</strong><br/>
<div id="ring">
<div id="inner-ring-container" style="">
<div id="inner-ring">
<script type="text/javascript">
for(i=0;i<key.length;i++) {
document.write('<div class="inner-ring-letter" style="-moz-transform:rotate('+((i*deg))+'deg);">'+key.charAt(i).toUpperCase()+'</div>');
}
</script>
</div>
</div>
<div id="outer-ring-container">
<div id="outer-ring">
<script type="text/javascript">
for(i=0;i<key.length;i++) {
document.write('<div class="outer-ring-letter" style="-moz-transform:rotate('+(i*(deg))+'deg);">'+key.charAt(i).toUpperCase()+'</div>');
}
</script>
</div> <!-- End outer Ring -->
</div> <!-- End Outer Ring Container -->
</div> <!-- End Ring -->
</div> <!-- End left container -->
</body>
</html>