Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created October 31, 2012 03:55
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 jasdev/3984698 to your computer and use it in GitHub Desktop.
Save jasdev/3984698 to your computer and use it in GitHub Desktop.
Blum Micali PRG
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;
}
}
@joy80
Copy link

joy80 commented Jun 8, 2016

why its a>(p-1)/2 in line no. 15?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment