summaryrefslogtreecommitdiff
path: root/js/arris.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/arris.js')
-rw-r--r--js/arris.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/js/arris.js b/js/arris.js
new file mode 100644
index 0000000..950ae33
--- /dev/null
+++ b/js/arris.js
@@ -0,0 +1,115 @@
+var sys = require("sys");
+
+function log(x) {
+// sys.print("" + x + "\n");
+}
+
+function calculatePasswordOfDay() {
+ var seedeight = "MPSJKMDH"
+ var seedten = "MPSJKMDHAI"
+
+ var sboxWeekday = [
+ [ 15, 15, 0x18, 20, 0x18 ],
+ [ 13, 14, 0x1b, 0x20, 10 ],
+ [ 0x1d, 14, 0x20, 0x1d, 0x18 ],
+ [ 0x17, 0x20, 0x18, 0x1d, 0x1d ],
+ [ 14, 0x1d, 10, 0x15, 0x1d ],
+ [ 0x22, 0x1b, 0x10, 0x17, 30 ],
+ [ 14, 0x16, 0x18, 0x11, 13 ] ]
+
+ var sbox2 = [
+ [ 0, 1, 2, 9, 3, 4, 5, 6, 7, 8 ],
+ [ 1, 4, 3, 9, 0, 7, 8, 2, 5, 6 ],
+ [ 7, 2, 8, 9, 4, 1, 6, 0, 3, 5 ],
+ [ 6, 3, 5, 9, 1, 8, 2, 7, 4, 0 ],
+ [ 4, 7, 0, 9, 5, 2, 3, 1, 8, 6 ],
+ [ 5, 6, 1, 9, 8, 0, 4, 3, 2, 7 ] ]
+
+ var sboxResult = [
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z' ]
+
+ var bufferWeekday = []
+ var bufferSeedEight = []
+ var buffer = []
+ var buffer6 = []
+ var bufferResult = []
+
+ var year = 2010 % 1000;
+ var month = 10;
+ var day = 20;
+ var weekday = 3-1;
+
+
+ bufferWeekday[0] = sboxWeekday[weekday][0];
+ bufferWeekday[1] = sboxWeekday[weekday][1];
+ bufferWeekday[2] = sboxWeekday[weekday][2];
+ bufferWeekday[3] = sboxWeekday[weekday][3];
+ bufferWeekday[4] = sboxWeekday[weekday][4];
+ bufferWeekday[5] = day;
+ if (((year + month) - day) < 0) {
+ bufferWeekday[6] = ((((year + month) - day) + 0x24) % 0x24);
+ } else {
+ bufferWeekday[6] = (((year + month) - day) % 0x24);
+ }
+ bufferWeekday[7] = ((((3 + ((year + month) % 12)) * day) % 0x25) % 0x24);
+ log("bufferWeekday=" + bufferWeekday)
+
+ bufferSeedEight[0] = seedeight.charCodeAt(0) % 0x24;
+ bufferSeedEight[1] = seedeight.charCodeAt(1) % 0x24;
+ bufferSeedEight[2] = seedeight.charCodeAt(2) % 0x24;
+ bufferSeedEight[3] = seedeight.charCodeAt(3) % 0x24;
+ bufferSeedEight[4] = seedeight.charCodeAt(4) % 0x24;
+ bufferSeedEight[5] = seedeight.charCodeAt(5) % 0x24;
+ bufferSeedEight[6] = seedeight.charCodeAt(6) % 0x24;
+ bufferSeedEight[7] = seedeight.charCodeAt(7) % 0x24;
+ log("bufferSeedEight=" + bufferSeedEight)
+
+ buffer[0] = (bufferWeekday[0] + bufferSeedEight[0]) % 0x24
+ buffer[1] = (bufferWeekday[1] + bufferSeedEight[1]) % 0x24
+ buffer[2] = (bufferWeekday[2] + bufferSeedEight[2]) % 0x24
+ buffer[3] = (bufferWeekday[3] + bufferSeedEight[3]) % 0x24
+ buffer[4] = (bufferWeekday[4] + bufferSeedEight[4]) % 0x24
+ buffer[5] = (bufferWeekday[5] + bufferSeedEight[5]) % 0x24
+ buffer[6] = (bufferWeekday[6] + bufferSeedEight[6]) % 0x24
+ buffer[7] = (bufferWeekday[7] + bufferSeedEight[7]) % 0x24
+ buffer[8] = (buffer[0] + buffer[1] + buffer[2] + buffer[3] + buffer[4] + buffer[5] + buffer[6] + buffer[7]) % 0x24
+ var bufferNum = buffer[8] % 6
+ buffer[9] = Math.round( Math.pow(bufferNum,2) )
+ log("buffer=" + buffer)
+
+ buffer6[0] = buffer[sbox2[bufferNum][0]]
+ buffer6[1] = buffer[sbox2[bufferNum][1]]
+ buffer6[2] = buffer[sbox2[bufferNum][2]]
+ buffer6[3] = buffer[sbox2[bufferNum][3]]
+ buffer6[4] = buffer[sbox2[bufferNum][4]]
+ buffer6[5] = buffer[sbox2[bufferNum][5]]
+ buffer6[6] = buffer[sbox2[bufferNum][6]]
+ buffer6[7] = buffer[sbox2[bufferNum][7]]
+ buffer6[8] = buffer[sbox2[bufferNum][8]]
+ buffer6[9] = buffer[sbox2[bufferNum][9]]
+ log("buffer6=" + buffer6)
+
+ bufferResult[0] = ((seedten.charCodeAt(0) + buffer6[0]) % 0x24);
+ bufferResult[1] = ((seedten.charCodeAt(1) + buffer6[1]) % 0x24);
+ bufferResult[2] = ((seedten.charCodeAt(2) + buffer6[2]) % 0x24);
+ bufferResult[3] = ((seedten.charCodeAt(3) + buffer6[3]) % 0x24);
+ bufferResult[4] = ((seedten.charCodeAt(4) + buffer6[4]) % 0x24);
+ bufferResult[5] = ((seedten.charCodeAt(5) + buffer6[5]) % 0x24);
+ bufferResult[6] = ((seedten.charCodeAt(6) + buffer6[6]) % 0x24);
+ bufferResult[7] = ((seedten.charCodeAt(7) + buffer6[7]) % 0x24);
+ bufferResult[8] = ((seedten.charCodeAt(8) + buffer6[8]) % 0x24);
+ bufferResult[9] = ((seedten.charCodeAt(9) + buffer6[9]) % 0x24);
+ log("bufferResult=" + bufferResult)
+
+ var out = "";
+ for (var i = 0; i < bufferResult.length; i++) {
+ out += sboxResult[ bufferResult[i] ]
+ }
+ return out;
+}
+
+
+sys.print(calculatePasswordOfDay() + "\n")