Exemplo n.º 1
0
  public RSA(Random random) {
    savedRandom = random;

    p = getPrime(random); // p and q are arbitrary large primes
    q = getPrime(random);
    n = p.multiply(q);
    phiN = (p.subtract(ONE)).multiply(q.subtract(ONE));

    S = getPrime(random); // s is an arbitrary secret; we'll use a prime
    V = S.modPow(new BigInteger("2"), n);
  }
Exemplo n.º 2
0
 private void makeKeys() {
   PrimeGenerator pg = new PrimeGenerator(513, 10, sr);
   do {
     p = pg.getStrongPrime();
   } while (p.subtract(BigIntegerMath.ONE).mod(BigIntegerMath.THREE).equals(BigIntegerMath.ZERO));
   do {
     q = pg.getStrongPrime();
   } while (q.subtract(BigIntegerMath.ONE).mod(BigIntegerMath.THREE).equals(BigIntegerMath.ZERO));
   modulus = p.multiply(q);
   // Use 3 as enciphering exponent - OK since we are using salt
   decipherExp =
       BigIntegerMath.THREE.modInverse(
           p.subtract(BigIntegerMath.ONE).multiply(q.subtract(BigIntegerMath.ONE)));
   ciphertextBlockSize = (modulus.bitLength() - 1) / 8 + 1;
   // Maximum size of plaintext is 6 bytes less than ciphertext
   // 1 to get under modulus
   // 4 for the salt
   // 1 for a pad byte
   plaintextBlockSize = ciphertextBlockSize - 6;
 }
Exemplo n.º 3
0
  void start() throws IOException {
    BigInteger n = new BigInteger(reader.next());
    String s = reader.next();

    BigInteger answer = BigInteger.ONE;
    while (n.compareTo(BigInteger.ONE) > 0) {
      answer = answer.multiply(n);
      n = n.subtract(BigInteger.valueOf(s.length()));
    }
    writer.println(answer);
  }
Exemplo n.º 4
0
 void solve(int caseNum) {
   int n = in.nextInt();
   BigInteger[] past = new BigInteger[n], d = new BigInteger[n];
   for (int i = 0; i < n; i++) past[i] = new BigInteger(in.next());
   Arrays.sort(past);
   for (int i = 0; i < n; i++) d[i] = past[i].subtract(past[0]);
   for (int i = 2; i < n; i++) d[i] = d[i].gcd(d[i - 1]);
   BigInteger gcd = d[n - 1], mod = past[0].mod(gcd);
   System.out.printf("Case #%d: ", caseNum);
   if (mod.equals(BigInteger.ZERO)) System.out.println(0);
   else System.out.println(gcd.subtract(mod));
 }