PackageOrg.colin.utils;ImportJava.util.Arrays;/** * Invitation Code Tool class * @author Colin * * Public class invitationcodeutils { Private Static FinalString[] M1 = {"A","W","Z","J","M","N","7","U","S","C","8","R","F","4","9","G","H","D","Y","K","6","V","3","B","2","E","T","L","P","Q","5","X"};Private Static FinalString[] M2 = {"T","V","G","Z","J","W","4","L","Q","N","K","Y","2","5","9","D","H","E","B","X","S","A","M","8","U","7","3","C","P","R","F","6"};Private Static FinalString[] M3 = {"9","K","R","V","J","S","M","N","W","C","U","D","X","Q","8","5","H","F","B","A","L","2","P","6","3","Y","Z","T","7","G","E","4"};Private Static FinalString[] M4 = {"E","F","U","G","A","9","8","L","M","5","7","X","S","R","K","6","T","N","3","W","V","P","B","2","4","D","Z","Y","H","J","C","Q"};Private Static FinalString[] M5 = {"N","C","P","J","U","3","2","T","L","S","9","W","Y","5","B","7","H","X","R","M","4","Z","K","E","Q","V","F","D","A","G","6","8"};Private Static FinalString[] M6 = {"F","P","9","S","C","B","7","T","U","E","A","M","N","K","D","R","Z","X","H","5","W","3","V","G","2","4","J","6","Q","Y","8","L"};/** * Invitation code generator * @param ID is greater than or equal to 1 and less than or equal to 32^6 * @return ID corresponding to the 6-bit 32 binary invitation code */ Public Static FinalStringGenerate(LongID) {if(ID <1|| ID > Math.pow ( +,6)) {Throw NewRuntimeException ("failed to generate the invitation code >> parameter values are not within the specified range"); }intI1, I2, i3, I4, i5, I6; I1 = (int) ((ID-1)/Math.pow ( +,5)); I6 = (int) ((ID-1)% Math.pow ( +,5)); I2 = (int) (I6/math.pow ( +,4)); I6 = (int) (I6% Math.pow ( +,4)); i3 = (int) (I6/math.pow ( +,3)); I6 = (int) (I6% Math.pow ( +,3)); I4 = (int) (I6/math.pow ( +,2)); I6 = (int) (I6% Math.pow ( +,2)); i5 = I6/ +; I6 = I6% +;returnM1[I1] + M2[i2] + M3[i3] + M4[i4] + m5[i5] + m6[i6]; }/** * Invitation Code parser * @param code 6-bit 32-in-One invitation code * @return The ID of the invitation code */ Public Static Final Long Parse(String code) {if(Code.length ()! =6) {Throw NewRuntimeException ("Parse Authenticode failed >> Invalid invitation code"); } string[] arr = Code.split ("");intI1, I2, i3, I4, i5, I6; I1 = Arrays.aslist (M1). IndexOf (arr[0]); I2 = Arrays.aslist (M2). IndexOf (arr[1]); i3 = Arrays.aslist (M3). IndexOf (arr[2]); I4 = Arrays.aslist (M4). IndexOf (arr[3]); i5 = arrays.aslist (M5). IndexOf (arr[4]); I6 = Arrays.aslist (M6). IndexOf (arr[5]);if(I1 = =-1|| I2 = =-1|| i3 = =-1|| I4 = =-1|| i5 = =-1|| I6 = =-1) {Throw NewRuntimeException ("Parse Authenticode failed >> Invalid invitation code"); }return(Long) (I1 * MATH.POW ( +,5) + I2 * MATH.POW ( +,4) + i3 * MATH.POW ( +,3) + I4 * MATH.POW ( +,2) + i5 * ++ I6 +1); }}
Invite Code Tool class