-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeyGenerator.java
More file actions
52 lines (34 loc) · 1.07 KB
/
KeyGenerator.java
File metadata and controls
52 lines (34 loc) · 1.07 KB
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
import java.util.LinkedList;
class KeyGenerator{
static LinkedList <String> allPermutations;
static String armstrongDigits;
static{
armstrongDigits = "153704"; //unique digits of the armstrong number
allPermutations = new LinkedList<String>();
getPermutations(armstrongDigits, "");
}
String userKey;
KeyGenerator(int uid){
int i = uid % allPermutations.size();
userKey = allPermutations.get(i) ;//+ System.currentTimeMillis();
}
String getKey(){
return userKey;
}
private static void getPermutations(String set, String sol){
int i;
char currentDigit;
String restOfTheDigits;
if(set.length() == 1){
//result = sol + set
allPermutations.add( sol+set);
}else{
//for the digits of the set
for(i =0 ; i < set.length(); i++){
currentDigit = set.charAt(i);
restOfTheDigits = set.substring(0,i) + set.substring(i+1);
getPermutations(restOfTheDigits, sol + currentDigit);
}//for
}//else
}
}