All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.test.BigIntegersTest Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4. Note: this package includes the NTRU encryption algorithms.

There is a newer version: 1.74
Show newest version
package org.bouncycastle.crypto.test;

import java.math.BigInteger;

import org.bouncycastle.util.BigIntegers;
import org.bouncycastle.util.test.SimpleTest;
import org.bouncycastle.util.test.TestRandomData;

public class BigIntegersTest
    extends SimpleTest
{
    public String getName()
    {
        return "BigIntegers";
    }

    public void performTest()
        throws Exception
    {
        BigInteger min = BigInteger.valueOf(5);
        isTrue(min.equals(BigIntegers.createRandomPrime(min.bitLength(), 1,
            new TestRandomData(BigIntegers.asUnsignedByteArray(min)))));

        BigInteger max = BigInteger.valueOf(743);
        isTrue(max.equals(BigIntegers.createRandomPrime(max.bitLength(), 1,
            new TestRandomData(BigIntegers.asUnsignedByteArray(max)))));

        isTrue(1 == BigIntegers.asUnsignedByteArray(BigIntegers.ZERO).length);
        isTrue(1 == BigIntegers.getUnsignedByteLength(BigIntegers.ZERO));
        isTrue(1 == BigIntegers.getUnsignedByteLength(BigIntegers.ONE));
    }

    public static void main(String[] args)
        throws Exception
    {
        runTest(new BigIntegersTest());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy