56 lines
1.3 KiB
Dart
56 lines
1.3 KiB
Dart
class Encryptor{
|
|
static String charPool = "AKFLDJAHSPIWUROCNMZX";
|
|
|
|
static String intToString(int input){
|
|
String output = "";
|
|
for(int i=0; i < input.toString().length; i++){
|
|
output += charPool[int.parse(input.toString()[i])];
|
|
}
|
|
|
|
int luckyNumber = GetLuckyNumber(input);
|
|
|
|
String lastLetter = charPool[luckyNumber];
|
|
|
|
return output + lastLetter;
|
|
}
|
|
|
|
static int stringToInt(String input){
|
|
String output = "";
|
|
for(int i=0; i < input.length-1; i++){
|
|
for(int j=0; j < charPool.length; j++){
|
|
if(charPool[j] == input[i]){
|
|
output += j.toString();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
String lastChar = input[input.length-1];
|
|
|
|
int outputInt = int.parse(output);
|
|
String luckyChar = charPool[GetLuckyNumber(outputInt)];
|
|
bool validated = luckyChar == lastChar;
|
|
|
|
if(validated){
|
|
return outputInt;
|
|
}else{
|
|
print("Error validating User ID, expected $luckyChar got $lastChar");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
static int GetLuckyNumber(int input){
|
|
int luckyNumber = input;
|
|
|
|
while(luckyNumber >= 10){
|
|
int val = 0;
|
|
for(int i=0; i < luckyNumber.toString().length; i++){
|
|
val+= int.parse(luckyNumber.toString()[i].toString());
|
|
}
|
|
|
|
luckyNumber = val;
|
|
}
|
|
|
|
return luckyNumber;
|
|
}
|
|
} |