Permalink
Browse files

forgot to add bigint and random?

  • Loading branch information...
estark37 committed Jun 9, 2011
1 parent 3755622 commit e3bfa35fc895479e8fd454a7f3b6f08917ef3b59
Showing with 14 additions and 6 deletions.
  1. +3 −1 bigint.js
  2. +11 −5 random.js
View
@@ -30,6 +30,8 @@ if (!navigator.javaEnabled()) {
}
} */
} else {
+ USE_SJCL = false;
+}
BigInt = Class.extend({
init: function(value, radix) {
@@ -200,4 +202,4 @@ $(document).ready(function() {
BigInt.use_applet = check_applet();
});
-}
+//}
View
@@ -8,7 +8,7 @@ Random = {};
Random.GENERATOR = null;
Random.setupGenerator = function() {
- if (Random.GENERATOR == null) {
+ if (Random.GENERATOR == null && !USE_SJCL) {
if (BigInt.use_applet) {
var foo = BigInt.APPLET.newSecureRandom();
Random.GENERATOR = BigInt.APPLET.newSecureRandom();
@@ -21,23 +21,29 @@ Random.setupGenerator = function() {
};
Random.getRandomInteger = function(max) {
- Random.setupGenerator();
var bit_length = max.bitLength();
+ Random.setupGenerator();
var random;
- if (BigInt.use_applet) {
+ if (USE_SJCL) {
+ random = sjcl.random.randomWords(bit_length / 32, 0);
+ // we get a bit array instead of a BigInteger in this case
+ var rand_bi = new BigInt(sjcl.codec.hex.fromBits(random), 16);
+ return rand_bi.mod(max);
+ } else if (BigInt.use_applet) {
random = BigInt.APPLET.randomBigInteger(bit_length, Random.GENERATOR);
} else {
random = new java.math.BigInteger(bit_length, Random.GENERATOR);
}
-
return BigInt._from_java_object(random).mod(max);
};
Random.getRandomPrime = function(n_bits) {
Random.setupGenerator();
var certainty = 80;
var prime;
- if (BigInt.use_applet) {
+ if (USE_SJCL) {
+ throw "getRandomPrime not implemented for SJCL";
+ } else if (BigInt.use_applet) {
prime = BigInt.APPLET.randomPrimeBigInteger(n_bits, certainty, Random.GENERATOR);
} else {
prime = new java.math.BigInteger(n_bits, certainty, Random.GENERATOR);

0 comments on commit e3bfa35

Please sign in to comment.