-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day10.js
89 lines (73 loc) · 1.78 KB
/
Day10.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
let list = new Array();
let lengths = [230,1,2,221,97,252,168,169,57,99,0,254,181,255,235,167];
let stringLengths = "oundnydw";
let ascii = [];
let toAdd = [17, 31, 73, 47, 23];
//
for(var i = 0; i < stringLengths.length; i++) {
ascii.push(stringLengths.charCodeAt(i));
}
ascii = ascii.concat(toAdd);
//////////
for (var i = 0; i < 256; i++) {
list.push(i);
}
let position = 0;
let skipSize = 0;
lengths.forEach(function(length) {
let tempList = [];
for (var i = position; i < position + length; i++) {
tempList.push(list[i%256]);
}
tempList = tempList.reverse();
let index = 0;
for (var i = position; i < position + length; i++) {
list[i%256] = tempList[index];
index++;
}
position =(position + length + skipSize)%256;
skipSize++;
});
console.log("Answer 1: " + list[0] * list[1]);
list = [];
for (var i = 0; i < 256; i++) {
list.push(i);
}
let count = 0;
position = 0;
skipSize = 0;
while(count < 64) {
ascii.forEach(function(length) {
let tempList = [];
for (var i = position; i < position + length; i++) {
tempList.push(list[i%256]);
}
tempList = tempList.reverse();
let index = 0;
for (var i = position; i < position + length; i++) {
list[i%256] = tempList[index];
index++;
}
position =(position + length + skipSize)%256;
skipSize++;
});
count++;
}
count = 0;
let denseArr = [];
while(count < 16) {
let denseHash = '';
for(var i = count*16; i < (count+1)*16; i++) {
denseHash = denseHash + list[i].toString();
if (i !== (count+1)*16-1) denseHash = denseHash + '^';
}
denseArr.push(eval(denseHash));
count++;
}
let finalString = '';
denseArr.forEach(function(num) {
let numString = num.toString(16);
if(numString.length < 2) numString = '0' + numString;
finalString = finalString + numString;
});
console.log("Answer 2: " + finalString);