Skip to content

Instantly share code, notes, and snippets.

@adison
Last active August 29, 2015 14:28
Show Gist options
  • Save adison/6e3187918dd321459dbe to your computer and use it in GitHub Desktop.
Save adison/6e3187918dd321459dbe to your computer and use it in GitHub Desktop.
java xor chemsum
import java.util.*;
import java.util.Random;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
class Untitled {
public static void main(String[] args) {
int lim = 1000000;
Set<String> returnList = new HashSet<>();
char spaces[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'};
Random ran = new Random();
byte[] seq = new byte[10];
char[] seqString = new char[10];
String ss = "";
Byte x = seq[0];
int last = 0;
// 算月份, 同一活動
seq[0] = 'a';
seq[1] = 'h';
seq[2] = '3';
seq[3] = 'y';
seqString[0] = 'a';
seqString[1] = 'h';
seqString[2] = '3';
seqString[3] = 'y';
Date oo = new Date();
int j=0;
int ri = 0;
// 跑一萬次
while (returnList.size() <= lim) {
// 跑 5 次隨機
for(int i=0, ii=5; i< ii; i++){
ri = ran.nextInt(spaces.length);
seq[i+4] = (byte)spaces[ri];
seqString[i+4] = spaces[ri];
}
x = seq[0];
for(int i=0, ii=9; i<ii; i++){
x= (byte)(x^seq[i]);
}
last = x.intValue() % (spaces.length);
seqString[9]= spaces[last];
// real String
ss = String.copyValueOf(seqString);
returnList.add(ss);
if(j%10000 ==0) {
System.out.print(String.format("%012d, %s\n", j, ss));
}
j++;
}
System.out.print(String.format("%d 次\n",j));
// String[] GPXFILES1 = returnList.toArray(new String[returnList.size()]);
// for (int i = 0; i < lim; i++) {
// System.out.print(String.format("%012d: %s\n", i, GPXFILES1[i]));
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment