Package: libnum
libnumThis is a python library for some numbers functions:working with primes (generating, primality tests)common maths (gcd, lcm, n'th root)modular arithmetics (inverse, Jacobi symbol, square root, solve CRT)converting strings to numbers or binary stringsLibrary may be used for learning/experimenting/research purposes. Should NOT be used for secure crypto implementations.Installation$pipinstalllibnumNote that only Python 3 version is maintained.DevelopmentFor development or building this repository,poetryis needed.Tests can be ran with$pytest--doctest-modules.List of functionsCommon mathslen_in_bits(n) - number of bits in binary representation of @nrandint_bits(size) - random number with a given bit sizeextract_prime_power(a, p) - s,t such that a = p**s * tnroot(x, n) - truncated n'th root of xgcd(a, b, ...) - greatest common divisor of all argumentslcm(a, b, ...) - least common multiplier of all argumentsxgcd(a, b) - Extented Euclid GCD algorithm, returns (x, y, g) : a * x + b * y = gcd(a, b) = gModularhas_invmod(a, n) - checks if a has modulo inverseinvmod(a, n) - modulo inversesolve_crt(remainders, modules) - solve Chinese Remainder Theoremefactorial_mod(n, factors) - compute factorial modulo composite number, needs factorizationnCk_mod(n, k, factors) - compute combinations number modulo composite number, needs factorizationnCk_mod_prime_power(n, k, p, e) - compute combinations number modulo prime powerModular square rootsjacobi(a, b) - Jacobi symbolhas_sqrtmod_prime_power(a, p, k) - checks if a number has modular square root, modulus is p**ksqrtmod_prime_power(a, p, k) - modular square root by p**khas_sqrtmod(a, factors) - checks if a composite number has modular square root, needs factorizationsqrtmod(a, factors) - modular square root by a composite modulus, needs factorizationPrimesprimes(n) - list of primes not greater than @n, slow methodgenerate_prime(size, k=25) - generates a pseudo-prime with @size bits length. @k is a number of tests.generate_prime_from_string(s, size=None, k=25) - generate a pseudo-prime starting with @s in string representationFactorizationis_power(n) - check if @n is p**k, k >= 2: return (p, k) or Falsefactorize(n) - factorize @n (currently with rho-Pollard method)
warning: format of factorization is now dict like {p1: e1, p2: e2, ...}ECCCurve(a, b, p, g, order, cofactor, seed) - class for representing elliptic curve. Methods:.is_null(p) - checks if point is null.is_opposite(p1, p2) - checks if 2 points are opposite.check(p) - checks if point is on the curve.check_x(x) - checks if there are points with given x on the curve (and returns them if any).find_points_in_range(start, end) - list of points in range of x coordinate.find_points_rand(count) - list of count random points.add(p1, p2) - p1 + p2 on elliptic curve.power(p, n) - n✕P or (P + P + ... + P) n times.generate(n) - n✕G.get_order(p, limit) - slow method, trying to determine order of p; limit is max order to tryConvertings2n(s) - packed string to numbern2s(n) - number to packed strings2b(s) - packed string to binary stringb2s(b) - binary string to packed stringStuffgrey_code(n) - number in Grey coderev_grey_code(g) - number from Grey codenCk(n, k) - number of combinationsfactorial(n) - factorialAboutAuthor: hellmanLicense:MIT License