-
-
Save nelenkov/581f9be65dcc0b6b35b9 to your computer and use it in GitHub Desktop.
Crude POC for repeating random numbers in Android. Let it run till the PID wraps a few times (pid_max is 32768, set to 1000 for faster turnaround), then find duplicates with something like this: select pid,rand,count(*) from rand group by pid,rand having count(*) > 1 order by count(*) desc;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity { | |
private static final String TAG = MainActivity.class.getSimpleName(); | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
generateRandom(); | |
} | |
private void generateRandom() { | |
SecureRandom sr = new SecureRandom(); | |
int pid = android.os.Process.myPid(); | |
Log.d(TAG, "PID: " + pid); | |
Log.d(TAG, "SecureRandom: " + sr.getClass().getName()); | |
Log.d(TAG, "SecureRandom provider: " + sr.getProvider().getName()); | |
byte[] bytes = new byte[8]; | |
sr.nextBytes(bytes); | |
String rand = Crypto.toHex(bytes); | |
Log.d(TAG, "Got: " + rand); | |
SQLiteOpenHelper db = new SQLiteOpenHelper(this, "rand.db", null, 1) { | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
String createTable = "create table rand(_id integer primary key autoincrement, pid integer not null, rand text not null)"; | |
db.execSQL(createTable); | |
} | |
@Override | |
public void onUpgrade(SQLiteDatabase db, int oldVersion, | |
int newVersion) { | |
} | |
}; | |
ContentValues values = new ContentValues(); | |
values.put("pid", pid); | |
values.put("rand", rand); | |
db.getWritableDatabase().insert("rand", null, values); | |
db.close(); | |
startActivity(new Intent(this, MainActivity.class)); | |
android.os.Process.killProcess(pid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment