Created
October 31, 2012 03:55
-
-
Save jasdev/3984698 to your computer and use it in GitHub Desktop.
Blum Micali PRG
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 Runner { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
//Generate the first 100 bits from Blum-Micali PRG with p = 34319, g = 4, and seed x = 1022 | |
long p = 34319; | |
long g = 4; | |
long x = 1022; | |
long a; | |
for(int i = 0; i < 100; i++){ | |
a = modExp(g, x, p); | |
if(a > (p-1)/2) | |
System.out.print("1"); | |
else | |
System.out.print("0"); | |
x = a; | |
} | |
} | |
public static long modExp(long g, long x, long p){ | |
long r = 1; | |
while(x > 0){ | |
if(x % 2 == 1) | |
r = r*g % p; | |
x = (long)Math.floor((double)x/2); | |
g = g*g % p; | |
} | |
return r; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why its a>(p-1)/2 in line no. 15?