Created
February 3, 2014 10:05
-
-
Save 0xBADCA7/8781301 to your computer and use it in GitHub Desktop.
Java's Random PRG "seed" prediction. Ideone ready.
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
/* 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