-
Notifications
You must be signed in to change notification settings - Fork 0
/
downtable.js
72 lines (66 loc) · 2.07 KB
/
downtable.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
/* Stella Downtable Encryption */
function encrypt(data, key){
var sourcemap = "abcdefghijklmnopqrstuvwxyz ABCEFGHIJKLMNOPQRSTUVWXYZ`¬!£$%^&*()_+1234567890-=[]{};'#:@~,./<>?\|"
var table = sourcemap.split("");
var datad = data;
var ackey = key;
var keyusage = "";
var mappedkey = [];
var currentround = 0;
var currentletter = 0;
var keyd = ackey.split("");
table.forEach(mapper);
var datamapped = datad.split("");
var output = "";
datamapped.forEach(encoder);
return output;
function encoder(item, index){
var indexintab = table.indexOf(item);
var mapoutput = mappedkey[indexintab] + ":";
output = output + mapoutput;
}
function mapper(item, index){
if (currentletter == ackey.length){
currentround = currentround + 1;
currentletter = 0;
}
var currentmapkey = keyd[currentletter];
var currentnumber = (keyusage.split(currentmapkey).length - 1);
keyusage = keyusage + currentmapkey;
mappedkey.push(currentmapkey + currentnumber);
currentletter = currentletter + 1;
}
}
function decode(data, key){
var sourcemap = "abcdefghijklmnopqrstuvwxyz ABCEFGHIJKLMNOPQRSTUVWXYZ`¬!£$%^&*()_+1234567890-=[]{};'#:@~,./<>?\|"
var table = sourcemap.split("");
var datad = data;
var ackey = key;
var keyusage = "";
var mappedkey = [];
var currentround = 0;
var currentletter = 0;
var keyd = ackey.split("");
table.forEach(mapper);
var datamapped = datad.split(":");
var output = "";
datamapped.splice(-1,1)
datamapped.forEach(decoder);
return output;
function decoder(item, index){
var indexintab = mappedkey.indexOf(item);
var mapoutput = table[indexintab];
output = output + mapoutput;
}
function mapper(item, index){
if (currentletter == ackey.length){
currentround = currentround + 1;
currentletter = 0;
}
var currentmapkey = keyd[currentletter];
var currentnumber = (keyusage.split(currentmapkey).length - 1);
keyusage = keyusage + currentmapkey;
mappedkey.push(currentmapkey + currentnumber);
currentletter = currentletter + 1;
}
}