Skip to content

Instantly share code, notes, and snippets.

@0xBADCA7
Created February 3, 2014 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xBADCA7/8781301 to your computer and use it in GitHub Desktop.
Save 0xBADCA7/8781301 to your computer and use it in GitHub Desktop.
Java's Random PRG "seed" prediction. Ideone ready.
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
private static long multiplier = 0x5DEECE66DL;
private static long addend = 0xBL;
private static long mask = (1L << 48) - 1;
public static void crack()
{
Random random = new Random();
long v1 = random.nextInt();
long v2 = random.nextInt();
for (int i = 0; i < 65536; i++)
{
long seed = (long)v1 * 65536 + i;
if ((((seed * multiplier + addend) & mask) >>> 16) == v2)
{
System.out.println("Seed found: " + seed);
break;
}
}
}
public static void main (String[] args) throws java.lang.Exception
{
crack();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment