Mathematical cryptography algorithms implemented in Python
Usage documentation will come later once the project is more complete, but for now, here's a basic overview:
Create a python script in the directory above this library and use import cryptomath
to import the entire library. From here, any completed functions can be accessed by referencing the library and function name, such as gcd = cryptomath.GCD(123,943)
, or gcd, x, y = cryptomath.ExtendedEuclidean(123, 10007)
.
To import only a specific module within the library, such as Factorization
, you may use from cryptomath import Factorization
. Then, the library will not need to be referenced, only the function names, such as fact = PrimeFactorization(1234)
. Similarly, you may import only one function of a module, which can be done with from cryptomath.Polynomials import JacobiSymbol
.
These are functions which have been finalized and can be effectively used:
- Euclidean(a, b), Alias: GCD(a, b)
- ExtendedEuclidean(a, b)
- ModularInv(a, n, prime (optional))
- FastPower(a, e, n)
- ChineseRemainderThm(a, m, b, n)
- Totient(x)
- PrimeFactorization(n)
- Factors(n, dup (optional))
- PollardP_1(n, b (optional))
- Pollard(n)
- GenerateProbablePrime(length)
- GeneratePrimes(n)
- JacobiSymbol(a, n)
- IsModSquare(a, n)
- TonelliShanks(a, n)
- ModSquareRoots(a, n)
- EulerTest(a, n)
- SolovayStrassenTest(n, tries (optional))
- FermatTest(a, n)
- MillerRabin(n, warnings (optional))
- IsPrime(n)
- IsSophieGermainPrime(n)
- Order(a, n)
- HammingWeight(x)
- SquareFree(x)
- SHOULD ADD: check that inputs are integers in every function
- Needs further testing:
- IsPrimRoot()
- PrimRoots()
- Use 'secrets' instead of 'random' for cryptographically secure random number generation: https://docs.python.org/3/library/secrets.html
- On parallelization of random number generation: https://ieeexplore.ieee.org/document/5547156
- Hensel's Lemma
- Modular Quadratic Solver
- Rabin Cipher
- Affine Cipher
- Pohlig-Hellman
- Shanks Babystep-Giantstep
- Primitive Roots
- Sophie Germain Strong Primes
- McEliece Public Key
- El Gamal
- RSA
- Merkle-Hellman
- Koblitz (elliptic Curves)
- Quadratic Sieve
- Lenstra's Algorithm (elliptic curves)
- Blakely (hyperplanes)
- Shamir (points)
- Basic
- Fiege-Fiat-Shamir
- Check if Point is on a Curve
- Add Points
- Point-Scalar Multiplication
- Diffie-Hellman
- RSA
- El Gamal