Last active
October 10, 2017 06:20
-
-
Save asanso/3f9759f9bb03fe42b86202e71b2f4293 to your computer and use it in GitHub Desktop.
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 gist; | |
import java.math.BigInteger; | |
import java.security.SecureRandom; | |
public class MSDBRG { | |
private static BigInteger TWO = new BigInteger("2"); | |
public static void main(String[] args) { | |
BigInteger bk = TWO.pow(256); | |
BigInteger bkoutput = TWO.pow(384); | |
BigInteger bk128 = TWO.pow(128); | |
BigInteger c1 = new BigInteger("297"); | |
BigInteger c2 = new BigInteger("357"); | |
BigInteger p = bk.add(c1); | |
BigInteger q = bk.add(c2); | |
BigInteger n = p.multiply(q); | |
BigInteger e = new BigInteger("7"); | |
BigInteger random = new BigInteger(128, new SecureRandom()); | |
BigInteger ct = random.modPow(e, n); | |
BigInteger y = ct.mod(bkoutput); | |
BigInteger x = ct.divide(bkoutput); | |
System.out.println("output of the generator is "+ y.toString(2)); | |
System.out.println("internal state of the generator is "+ x.toString(2)); | |
//WORKING WITH THE OUTPUT ONLY Y | |
String ys = y.toString(2); | |
//taking the 128 most significant bits of the output | |
BigInteger ym = new BigInteger(ys.substring(0,128),2); | |
//taking the 256 less significant bits of the output | |
BigInteger yl = new BigInteger(ys.substring(128),2); | |
System.out.println(); | |
System.out.println("===================================================================="); | |
System.out.println("CT mod p is "+ ct.mod(p).toString(2)); | |
System.out.println("CT mod p is "+crandalMod(ym, yl, bk, c1).toString(2)); | |
System.out.println("===================================================================="); | |
System.out.println("CT mod p (128 lbt) "+ ct.mod(p).mod(bk128).toString(2)); | |
System.out.println("CT mod p (128 lbt) "+crandalMod(ym, yl, bk, c1).mod(bk128).toString(2)); | |
} | |
public static BigInteger crandalMod(BigInteger ym, BigInteger yl, BigInteger bk, BigInteger c) { | |
BigInteger r = yl; | |
BigInteger r1 = ym.multiply(c); | |
r = r.subtract(r1); | |
r = r.add(c); | |
return r; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment