forked from borfast/arrispwgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrisPwdGen.java
222 lines (188 loc) · 7.59 KB
/
ArrisPwdGen.java
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
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
public class ArrisPwdGen {
private Date startDate;
private Date endDate;
private static final String seed = "MPSJKMDHAI";
private static int[][] table1 = {
{15, 15, 24, 20, 24},
{13, 14, 27, 32, 10},
{29, 14, 32, 29, 24},
{23, 32, 24, 29, 29},
{14, 29, 10, 21, 29},
{34, 27, 16, 23, 30},
{14, 22, 24, 17, 13}
};
private static int[][] table2 = {
{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}
};
private static char[] alphanum = {
'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'
};
public ArrisPwdGen() {
}
public HashMap<String, String> GenArrisPasswords() {
if (startDate == null) {
startDate = new Date();
}
if (endDate == null) {
endDate = new Date (startDate.getTime());
}
int password_count = 0;
long one_day_in_milliseconds = 24 * 60 * 60 * 1000; // 1 day in milliseconds
// Check how many passwords we're going to generate.
password_count = (int)Math.ceil((endDate.getTime() - startDate.getTime() + 1) / one_day_in_milliseconds) + 1;
// See if we have a valid number of passwords
if ((password_count < 1) || (password_count > 365)) {
System.out.println("Invalid dates. I need dates that span a year at most");
System.exit(-1);
}
String seedeight = seed.substring(0, 8);
String seedten = seed;
int[] list1 = new int[8];
int[] list2 = new int[8];
int[] list3 = new int[10];
int[] list4 = new int[10];
int[] list5 = new int[10];
int year = 0;
int month = 0;
int day_of_month = 0;
int day_of_week = 0;
int i;
long iter;
Date date = null;
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
HashMap<String, String> password_list = new HashMap<String, String>();
for (iter = 0; iter < password_count; iter++) {
// For each iteration advance the date one day
date = new Date(startDate.getTime() + (iter * one_day_in_milliseconds));
// Last two digits of the year
sdf = new SimpleDateFormat("yy");
year = Integer.parseInt(sdf.format(date), 10);
// Number of the month (no leading zero; January == 0)
sdf = new SimpleDateFormat("M");
month = Integer.parseInt(sdf.format(date), 10);
// Day of the month
sdf = new SimpleDateFormat("d");
day_of_month = Integer.parseInt(sdf.format(date), 10);
// Day of the week. Normally 0 would be Sunday but we need it to be Monday.
Calendar cal = Calendar.getInstance();
cal.setTime(date);
day_of_week = cal.get(Calendar.DAY_OF_WEEK) - 2;
if (day_of_week < 0) {
day_of_week = 6;
}
// Now build the lists that will be used by each other.
// list1
for (i = 0; i <= 4; i++) {
list1[i] = table1[day_of_week][i];
}
list1[5] = day_of_month;
if (((year + month) - day_of_month) < 0) {
list1[6] = (((year + month) - day_of_month) + 36) % 36;
} else {
list1[6] = ((year + month) - day_of_month) % 36;
}
list1[7] = (((3 + ((year + month) % 12)) * day_of_month) % 37) % 36;
// list2
for (i = 0; i <= 7; i++) {
list2[i] = (seedeight.substring(i, i+1).codePointAt(0)) % 36;
}
// list3
for (i = 0; i <= 7; i++) {
list3[i] = (((list1[i] + list2[i])) % 36);
}
list3[8] = (list3[0] + list3[1] + list3[2] + list3[3] + list3[4] +
list3[5] + list3[6] + list3[7]) % 36;
int num8 = (list3[8] % 6);
list3[9] = (int)Math.round(Math.pow(num8, 2));
// list4
for (i = 0; i <= 9; i++) {
list4[i] = list3[table2[num8][i]];
}
// list5
for (i = 0; i <= 9; i++) {
list5[i] = ((seedten.substring(i, i+1).codePointAt(0)) + list4[i]) % 36;
}
// Finally, build the password of the day.
String password_of_the_day = new String();
int len = list5.length;
for (i = 0; i < len; i++) {
password_of_the_day += alphanum[list5[i]];
}
sdf = new SimpleDateFormat("yyyy-MM-dd");
password_list.put(sdf.format(date), password_of_the_day);
}
return password_list;
}
public static void printPasswords(HashMap<String, String> passMap) {
if (passMap != null) {
List<String> keys = new ArrayList<String>(passMap.keySet());
Collections.sort(keys);
Iterator i = keys.iterator();
while (i.hasNext()) {
String date = (String) i.next();
String pass = (String)passMap.get(date);
System.out.println(date+"\t"+pass);
}
}
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
if (startDate == null) {
this.startDate = null;
return;
}
SimpleDateFormat regularDateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
this.startDate = regularDateFormat.parse(startDate);
} catch (Exception e) {
System.out.println("Wrong start date "+startDate);
}
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
if (endDate == null) {
this.endDate = null;
return;
}
SimpleDateFormat regularDateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
this.endDate = regularDateFormat.parse(endDate);
} catch (Exception e) {
System.out.println("Wrong end date "+endDate);
}
}
public static void main(String[] args) {
ArrisPwdGen generator = new ArrisPwdGen();
String initialDate = null;
String finalDate = null;
if (args.length > 0) {
initialDate = args[0];
}
if (args.length > 1) {
finalDate = args[1];
}
generator.setStartDate(initialDate);
generator.setEndDate(finalDate);
ArrisPwdGen.printPasswords(generator.GenArrisPasswords());
}
}