-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenigmaCanv.html
More file actions
675 lines (590 loc) · 21.2 KB
/
enigmaCanv.html
File metadata and controls
675 lines (590 loc) · 21.2 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Permanent+Marker ' rel='stylesheet' type='text/css' />
<!--Enigma Functional Script-->
<script>
var encodings = {
0:{sequence:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",nch:""},
1:{sequence:"EKMFLGDQVZNTOWYHXUSPAIBRCJ",nch:"Q"},
2:{sequence:"AJDKSIRUXBLHWTMCQGZNPYFVOE",nch:"E"},
3:{sequence:"BDFHJLCPRTXVZNYEIWGAKMUSQO",nch:"V"},
4:{sequence:"ESOVPZJAYQUIRHXLNFTGKDCMWB",nch:"J"},
5:{sequence:"VZBRGITYUPSDNHLXAWMJQOFECK",nch:"Z"},
6:{sequence:"JPGVOUMFYQBENHZRDKASXLICTW",nch:"ZM"},
7:{sequence:"NZJHGRCXMYSWBOUFAIVLPEKQDT",nch:"ZM"},
8:{sequence:"FKQHTLXOCBJSPDZRAMEWNIUYGV",nch:"ZM"},
9:{sequence:"LEYJVCNIXWPBQMDRTAKZGFUHOS",nch:"",name:"Beta"},
10:{sequence:"FSOKANUERHMBTIYCWLQPZXVGJD",nch:"",name:"Gamma"},
A:{sequence:"EJMZALYXVBWFCRQUONTSPIKHGD",nch:""},
B:{sequence:"YRUHQSLDPXNGOKMIEBFZCWVJAT",nch:""},
C:{sequence:"FVPJIAOYEDRZXWGCTKUQSBNMHL",nch:""},
BThin:{sequence:"ENKQAUYWJICOPBLMDXZVFTHRGS",nch:""},
CThin:{sequence:"RDOBJNTKVEHMLFCWZAXGYIPSUQ",nch:""}
}
for(key in encodings) {encodings[key].sequence = encodings[key].sequence.split("");}
for(var x=1;x<9;x++) {encodings[x].nch = encodings[x].nch.split("");}
function charToIndex(char) {return(char.toUpperCase().charCodeAt(0) - 65)};
function indexToChar(idx) {return(String.fromCharCode(idx+65))};
function Rotor(number) {
this.number = number;
this.sequence = ([]).concat(encodings[number].sequence);
this.tracker = ([]).concat(encodings[0].sequence);
this.ring = ([]).concat(encodings[0].sequence);
this.notches = encodings[number].nch;
}
Rotor.prototype = {
constructor:Rotor,
setRing:function(ring) {
while(this.ring[0] != ring) {
this.ring.push(this.ring.shift());
}
},
setStart:function(n) {
while(this.ring[0] != n) {
this.advance();
}
},
advance:function() {
this.sequence.push(this.sequence.shift());
this.tracker.push(this.tracker.shift());
this.ring.push(this.ring.shift());
},
encode:function(letter) {
letter = this.sequence[charToIndex(letter)]
return(indexToChar(this.tracker.indexOf(letter)));
},
decode:function(letter) {
letter = this.tracker[charToIndex(letter)]
return(indexToChar(this.sequence.indexOf(letter)));
},
isNotched:function() {
if(this.notches.indexOf(this.ring[0]) !== -1) {
return(true);
}
return(false);
}
}
function createRotor(num,ring,start) {
var nr = new Rotor(num);
nr.setRing(ring);
nr.setStart(start);
return(nr);
}
function createReflector(name,start) {
var nr = new Rotor(name);
nr.setStart(start);
return(nr);
}
function encode(rotorSet,letter) {
var l = rotorSet.length;
var i = 0;
//console.log("Input letter is: " + letter);
while(i<l) {
letter = rotorSet[i].encode(letter);
//console.log("Rotor at index: " + i + " encodes to: " + letter);
i++;
}
i--;
while(i) {
i--;
letter = rotorSet[i].decode(letter)
//console.log("Rotor at index: " + i + " decodes to: " + letter);
}
return(letter);
}
function advance(rotorSet) {
rotorSet[0].advance();
var rotorCount = rotorSet.length - 1;
var tba = [];
for(var i=1;i<rotorCount;i++) {
if(rotorSet[i-1].isNotched() || (rotorSet[i].isNotched() && i!=rotorCount-1)) {
tba.push(i);
}
}
for(elem in tba) {
rotorSet[tba[elem]].advance();
}
}
function fourthRotor() {
var types = ["rot","ring","start"];
if(document.getElementById("4rotQ").checked) {
for(entry in types) {
entry = types[entry];
var nsel = document.createElement("select");
nsel.id = entry+"3";
if(entry == "rot") {
nsel.innerHTML = inner;
nsel.value = 4;
}
else {
nsel.innerHTML = alphaOpt;
nsel.value = "A";
}
var osel = document.getElementById(entry+"2");
osel.parentNode.insertBefore(nsel,osel);
}
}
else {
for(entry in types) {
entry = types[entry];
var nsel = document.getElementById(entry+"3");
nsel.parentNode.removeChild(nsel);
}
}
}
//var rotors = [createRotor(3,'a','a'),createRotor(2,'a','a'),createRotor(1,'a','a'),createReflector("B",'a')]
var rotors;
function setupRotors() {
function get(id) {return(document.getElementById(id));}
rotors = [createRotor(get("rot0").value,get("ring0").value,get("start0").value),
createRotor(get("rot1").value,get("ring1").value,get("start1").value),
createRotor(get("rot2").value,get("ring2").value,get("start2").value),
createReflector(get("refl").value,'A')];
if(get("4rotQ").checked) {
rotors.splice(3,0,createRotor(get("rot3").value,get("ring3").value,get("start3").value));
}
}
function updateDisplay() {
function get(id) {return(document.getElementById(id));}
get("start0").value = rotors[0].ring[0];
get("start1").value = rotors[1].ring[0];
get("start2").value = rotors[2].ring[0];
if(get("4rotQ").checked) {
get("start3").value = rotors[3].ring[0];
}
}
function sendOnKeyDown(e) {
var ob = document.getElementById("output");
var ccode = e.keyCode;
if(ccode < 65 || ccode > 90) {return;}
var char = String.fromCharCode(ccode);
advance(rotors);
updateDisplay();
var char = encode(rotors,char);
var ob = get("output")
ob.innerHTML += char;
if(ob.innerHTML.replace(/\s/g,'').length%4 == 0) {ob.innerHTML += ' ';}
return(char);
}
</script>
<!--Canvas Drawing Script-->
<script>
var keyOffsets = {
'Q':[0,0],'W':[1,0],'E':[2,0],'R':[3,0],'T':[4,0],'Z':[5,0],'U':[6,0],'I':[7,0],'O':[8,0],
'A':[0.5,1],'S':[1.5,1],'D':[2.5,1],'F':[3.5,1],'G':[4.5,1],'H':[5.5,1],'J':[6.5,1],'K':[7.5,1],
'P':[0,2],'Y':[1,2],'X':[2,2],'C':[3,2],'V':[4,2],'B':[5,2],'N':[6,2],'M':[7,2],'L':[8,2]};
var enigmaLayout = {
keysBase:[25,400],
keyGaps:[50,50],
lightBase:[25,200],
lightGaps:[50,50],
};
function fillRectNoise(canvas,ctx,x,y,width,height,size) {
var imgData = ctx.getImageData(x,y,width,height);
if(size == undefined) {size = width/2};
for(var xidx=0;xidx<width;xidx++) {
for(var yidx=0;yidx<height;yidx++) {
pixN = 4*(xidx+yidx*width);
px = xidx/width;
py = yidx/height; // normalize
var n = PerlinNoise.noise( size*px, size*py, 0.9 );
imgData.data[pixN+0] = imgData.data[pixN+1] = imgData.data[pixN+2] = Math.round(200*n);
}
}
ctx.putImageData(imgData,x,y);
}
function fillEllipse(canvas,ctx,cx,cy,rx,ry) {
var start = 0;
var end = 2 * Math.PI;
var circumference = 2*Math.max(rx,ry);
var scaleX = 2*rx / circumference;
var scaleY = 2*ry / circumference;
ctx.save();
ctx.translate(cx,cy);
ctx.scale(scaleX, scaleY);
ctx.beginPath();
ctx.arc(0,0,circumference/2,start,end,false);
ctx.closePath();
ctx.restore();
ctx.fill();
}
function get(id) {return(document.getElementById(id))}
function drawCanv() {
var canvas = get("enigmaCanv");
var ctx = canvas.getContext("2d");
canvas.width = canvas.width;
drawBkg(canvas,ctx);
var lc = 90;
while(lc-64) {
drawKey(canvas,ctx,String.fromCharCode(lc),false);
drawLight(canvas,ctx,String.fromCharCode(lc),false);
lc--;
}
ctx.fillStyle = "red";
}
function drawBkg(canvas,ctx) {
ctx.fillStyle = "#d6742d";
ctx.fillRect(10,10,canvas.width-20,canvas.height-20);
fillRectNoise(canvas,ctx,15,15,canvas.width-30,canvas.height-30);
ctx.fillStyle = "rgba(30,30,30,0.8)";
ctx.fillRect(15,15,canvas.width-30,canvas.height-30);
var slopeHeight = enigmaLayout.keysBase[1]-(enigmaLayout.lightBase[1]+2.8*enigmaLayout.lightGaps[1]);
var grad = ctx.createLinearGradient(0,enigmaLayout.keysBase[1]-slopeHeight,0,enigmaLayout.keysBase[1]);
grad.addColorStop(0,"rgba(0,0,0,0)");
grad.addColorStop(0.3,"rgba(0,0,0,0.3)");
grad.addColorStop(0.7,"rgba(0,0,0,0.3)");
grad.addColorStop(1,"rgba(0,0,0,0)");
ctx.fillStyle = grad;
ctx.fillRect(15,enigmaLayout.keysBase[1]-slopeHeight,canvas.width-30,slopeHeight);
}
function drawKey(canvas,ctx,key,state) {
var baseXY = enigmaLayout.keysBase;
var offsetSizes = enigmaLayout.keyGaps;
var rsx = offsetSizes[0]*0.8;
var rsy = offsetSizes[1]*0.8;
var x = baseXY[0] + offsetSizes[0]*keyOffsets[key][0];
var y = baseXY[1] + offsetSizes[1]*keyOffsets[key][1];
fillRectNoise(canvas,ctx,x,y,rsx,rsy);
ctx.fillStyle = "rgba(30,30,30,0.8)";
ctx.fillRect(x,y,rsx,rsy);
ctx.fillStyle = "#000";
fillEllipse(canvas,ctx,x+rsx*0.5,y+rsy*0.95,0.15*rsx,0.125*rsy);
ctx.fillStyle = "#999";
ctx.fillRect(x+0.4*rsx,y+0.5*rsy,0.2*rsx,0.45*rsy);
fillEllipse(canvas,ctx,x+0.5*rsx,y+0.95*rsy,0.1*rsx,0.075*rsy);
if(state) {y+=0.25*rsy;}
ctx.fillStyle = "#c8c8c8";
fillEllipse(canvas,ctx,x+0.5*rsx,y+0.35*rsy,0.5*rsx,0.35*rsy);
ctx.fillStyle = "#000";
fillEllipse(canvas,ctx,x+0.5*rsx,y+0.35*rsy,0.4*rsx,0.25*rsy);
var n = 'PQWERTZUIO'.split("").indexOf(key)
if(n != -1) {
ctx.font = String(0.25*rsy)+"px sans-serif";
ctx.textBaseline = "middle";
ctx.textAlign = "center";
ctx.fillStyle = "#fff";
ctx.fillText(key,x+0.5*rsx,y+0.5*rsy);
ctx.fillText(String(n),x+0.5*rsx,y+0.25*rsy);
}
else {
ctx.font = String(0.375*rsy)+"px sans-serif";
ctx.textBaseline = "middle";
ctx.textAlign = "center";
ctx.fillStyle = "#fff";
ctx.fillText(key,x+rsx*0.5,y+rsy*0.4);
}
}
function drawLight(canvas,ctx,light,state) {
var baseXY = enigmaLayout.lightBase;
var offsetSizes = enigmaLayout.lightGaps;
var rsx = offsetSizes[0]*0.8;
var rsy = offsetSizes[1]*0.8;
var x = baseXY[0] + offsetSizes[0]*keyOffsets[light][0];
var y = baseXY[1] + offsetSizes[1]*keyOffsets[light][1];
fillRectNoise(canvas,ctx,x,y,rsx,rsy);
ctx.fillStyle = "rgba(30,30,30,0.8)";
ctx.fillRect(x,y,rsx,rsy);
rsx *= 0.5;
rsy *= 0.35;
ctx.fillStyle = "#181818";
fillEllipse(canvas,ctx,x+rsx,y+rsy*0.75,rsx,rsy);
ctx.fillRect(x,y+rsy*0.75,rsx*2,rsy*0.25);
if(state) {ctx.fillStyle = "#282828";}
else {ctx.fillStyle = "#000";}
fillEllipse(canvas,ctx,x+rsx,y+rsy,rsx,rsy);
if(state) {ctx.fillStyle = "#ff9";}
else {ctx.fillStyle = "#bbb";}
rsy*=1.15;
ctx.font = String(rsy)+"px sans-serif";
ctx.textBaseline = "middle";
ctx.textAlign = "center";
ctx.fillText(light,x+rsx,y+rsy);
var n = 'PQWERTZUIO'.split("").indexOf(light)
if(n != -1) {
ctx.font = String(0.75*rsy)+"px sans-serif";
ctx.textBaseline = "middle";
ctx.textAlign = "center";
ctx.fillStyle = "#fff";
rsy*=2.7;
if(n) {rsy*=-0.4;}
ctx.fillText(String(n),x+rsx,y+rsy);
}
}
</script>
<!--Perlin Noise Script-->
<script>
/*Code for img generation
x /= w; y /= h; // normalize
size = 10; // pick a scaling value
n = PerlinNoise.noise( size*x, size*y, .8 );
r = g = b = Math.round( 255 * n );
*/
//
// This is a port of Ken Perlin's Java code. The
// original Java code is at http://cs.nyu.edu/%7Eperlin/noise/.
// Note that in this version, a number from 0 to 1 is returned.
PerlinNoise = new function() {
this.noise = function(x, y, z) {
var p = new Array(512)
var permutation = [ 151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
];
for (var i=0; i < 256 ; i++)
p[256+i] = p[i] = permutation[i];
var X = Math.floor(x) & 255, // FIND UNIT CUBE THAT
Y = Math.floor(y) & 255, // CONTAINS POINT.
Z = Math.floor(z) & 255;
x -= Math.floor(x); // FIND RELATIVE X,Y,Z
y -= Math.floor(y); // OF POINT IN CUBE.
z -= Math.floor(z);
var u = fade(x), // COMPUTE FADE CURVES
v = fade(y), // FOR EACH OF X,Y,Z.
w = fade(z);
var A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF
B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS,
return scale(lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD
grad(p[BA ], x-1, y , z )), // BLENDED
lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS
grad(p[BB ], x-1, y-1, z ))),// FROM 8
lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS
grad(p[BA+1], x-1, y , z-1 )), // OF CUBE
lerp(u, grad(p[AB+1], x , y-1, z-1 ),
grad(p[BB+1], x-1, y-1, z-1 )))));
}
function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); }
function lerp( t, a, b) { return a + t * (b - a); }
function grad(hash, x, y, z) {
var h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
var u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS.
v = h<4 ? y : h==12||h==14 ? x : z;
return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v);
}
function scale(n) { return (1 + n)/2; }
}
</script>
<!--Canvas Click Handling-->
<script>
function keyHandler(x,y,e) {
var keyChars = [['Q','W','E','R','T','Z','U','I','O'],
['A','S','D','F','G','H','J','K'],
['P','Y','X','C','V','B','N','M','L']];
var gap = enigmaLayout.keyGaps
x-=enigmaLayout.keysBase[0];
y-=enigmaLayout.keysBase[1];
if(y%gap[1] > 0.8*gap[1]) {return;}
y = Math.floor(y/gap[1]);
if(y%2) {x-=(0.5*gap[0]);}
if(x%gap[0] > 0.8*gap[0]) {return;}
x = Math.floor(x/gap[0]);
var char = keyChars[y][x];
if(e.type == "mousedown") {
pressKey(char);
}
if(e.type == "mouseup") {
releaseKey();
}
}
function canvasClickHandler(e) {
var bCRect = canvasG.getBoundingClientRect();
var x = canvasG.width*(e.clientX - bCRect.left)/bCRect.width;
var y = canvasG.height*(e.clientY - bCRect.top)/bCRect.height;
if(y>enigmaLayout.keysBase[1] && y<enigmaLayout.keysBase[1]+3*enigmaLayout.keyGaps[1]) {keyHandler(x,y,e);return;}
}
</script>
<!--Enigma High Level Events-->
<script>
var pk;
function pressKey(char) {
pk = char;
var kCode = char.charCodeAt(0);
drawKey(canvasG,ctxG,char,true);
var ec = sendOnKeyDown({'keyCode':kCode});
litChars[kCode] = ec;
drawLight(canvasG,ctxG,litChars[kCode],true);
}
function releaseKey() {
var char = pk;
var kCode = char.charCodeAt(0);
drawKey(canvasG,ctxG,char,false);
drawLight(canvasG,ctxG,litChars[kCode],false);
}
</script>
<style>
body {
background-color:#ccc;
}
#output {
display:block;
padding:10px;
float:right;
width:500px;
height:600px;
background: -webkit-linear-gradient(top, #000 0%, rgba(249,229,161,1) 8%) 0 4px;
-webkit-background-size: 100% 20px;
background-position:0 5%;
font-family: 'Permanent Marker', cursive;
font-size:15px;
}
</style>
</head>
<body>
<form id="enigmaSettings">
<div>
Rotor/Reflector Configuration:
<select id="refl">
<option value="A">A</option>
<option value="B" selected>B</option>
<option value="C">C</option>
<option value="BThin">B Thin</option>
<option value="CThin">C Thin</option>
</select>
<select id="rot2"></select>
<select id="rot1"></select>
<select id="rot0"></select>
(Four Rotors:<input id="4rotQ" type="checkbox" />)
<!--Populate Selects && Add Event Listener-->
<script>
//Build Options
var inner = "";
var rotOpt = {1:'I',2:'II',3:'III',4:'IV',5:'V',6:'VI',7:'VII',8:'VIII'};
for(key in rotOpt) {
inner += '<option value="'+key+'">'+rotOpt[key]+'</option>';
}
//Populate
for(var i=0;i<3;i++) {
document.getElementById("rot"+i).innerHTML = inner;
}
//Add Event Listener
document.getElementById("4rotQ").addEventListener("change",fourthRotor);
</script>
</div>
<div>
Ring Settings:
<select id="ring2"></select>
<select id="ring1"></select>
<select id="ring0"></select>
<!--Populate Selects-->
<script>
//Build Alphabet Options
var alphaOpt = "";
for(var i=65;i<91;i++) {
var char = String.fromCharCode(i);
alphaOpt += '<option value="' + char +'">' + char + '</option>';
}
//Populate
for(var i=0;i<3;i++) {
document.getElementById("ring"+i).innerHTML = alphaOpt;
}
</script>
</div>
<div>
Ground Settings:
<select id="start2"></select>
<select id="start1"></select>
<select id="start0"></select>
<!--Populate Selects-->
<script>
//Populate
for(var i=0;i<3;i++) {
document.getElementById("start"+i).innerHTML = alphaOpt;
}
</script>
</div>
</form>
<div>
<input type="text" id="input"/>
<span id="output"> </span>
</div>
<!--Default Settings && Event Listeners && Focus-->
<script>
var defaultSettings = {"rot0":3,"rot1":2,"rot2":1,
"ring0":"A","ring1":"A","ring2":"A",
"start0":"A","start1":"A","start2":"A"};
//Apply default settings
for(entry in defaultSettings) {
document.getElementById(entry).value = defaultSettings[entry];
}
setupRotors();
//Event Listeners
//get("input").addEventListener("keyup",send);
get("enigmaSettings").addEventListener("change",function(){setupRotors();updateDisplay();});
</script>
<canvas width="500" height="600" id="enigmaCanv"></canvas>
<script>
drawCanv();
//Canvas Vars
var canvasG = get("enigmaCanv");
var ctxG = canvasG.getContext("2d");
var litChars={};
get("input").addEventListener("keydown",function(e){
if(e.repeat == false && e.keyCode<91 && e.keyCode>64) {
pressKey(String.fromCharCode(e.keyCode));
}
});
get("input").addEventListener("keyup",function(e) {
if(e.repeat == false && e.keyCode<91 && e.keyCode>64) {
get("input").value = "";
releaseKey(String.fromCharCode(e.keyCode))
}
});
//Detect touch and set event listeners &| keyboard focus if not
function isTouchDevice() {
return (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0));
}
if(isTouchDevice()) {
canvasG.addEventListener("touchstart",function(e){e.changedTouches[0].type = "mousedown";
canvasClickHandler(e.changedTouches[0])});
canvasG.addEventListener("touchend",function(e){e.changedTouches[0].type = "mouseup";
canvasClickHandler(e.changedTouches[0])});
}
else {
canvasG.addEventListener("mousedown",canvasClickHandler);
canvasG.addEventListener("mouseup",canvasClickHandler);
get("input").focus();
}
</script>
</body>
</html>
<!--
ROTOR ENCODING (RING A/1) NOTCH
----------------------------------------
I EKMFLGDQVZNTOWYHXUSPAIBRCJ Q
II AJDKSIRUXBLHWTMCQGZNPYFVOE E
III BDFHJLCPRTXVZNYEIWGAKMUSQO V
IV ESOVPZJAYQUIRHXLNFTGKDCMWB J
V VZBRGITYUPSDNHLXAWMJQOFECK Z
VI JPGVOUMFYQBENHZRDKASXLICTW Z,M
VII NZJHGRCXMYSWBOUFAIVLPEKQDT Z,M
VIII FKQHTLXOCBJSPDZRAMEWNIUYGV Z,M
REFLECTOR ENCODING
---------------------------------------
A EJMZALYXVBWFCRQUONTSPIKHGD
B YRUHQSLDPXNGOKMIEBFZCWVJAT
C FVPJIAOYEDRZXWGCTKUQSBNMHL
BThin ENKQAUYWJICOPBLMDXZVFTHRGS
CThin RDOBJNTKVEHMLFCWZAXGYIPSUQ
Beta LEYJVCNIXWPBQMDRTAKZGFUHOS
Gamma FSOKANUERHMBTIYCWLQPZXVGJD
The Beta and Gamma "rotors" are actually just an
addon for the thin reflectors to allow more
variation and so lack notches...
Rotors advance if either the preceding rotor's
notch is exposed or if its own notch is exposed.
(Double stepping)
Still need to do the Steckerbrecht
TODO:
- Stecker logic & graphics
- Rotors graphics
-->