summaryrefslogtreecommitdiff
path: root/js/arris.js
blob: 228b54e1dc8ee37775d7033ac635bed73d7ebe65 (plain)
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
/*
var sys = require("sys")

function log(x) {
    sys.print("" + x + "\n")
}
*/

function calculatePasswordOfDay(date) {
    if (typeof(log) == "undefined") {
        var log = function(msg) { }
    }

    var year = (date.getYear()+1900) % 1000
    var month = date.getMonth()+1
    var day = date.getDate()
    var weekday = ( date.getDay() - 1 + 7 ) % 7;
    console.debug(weekday)

    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 = []
   			
    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(new Date()) + "\n")
*/