Galois Script
This scripting language lets you use arbitrarily large integers and binary polynomials directly in the code, along with a library of handy functions for finite Galois fields and elliptic curves. It is a modified version of JavaScript where the ^ operator performs exponentiation, and operators can be used on various data types (numbers, polynomials, and elliptic curves) according to their own operations. For modular exponentiation, you should always use the pow() function, since it proactively keeps the answer less than the modulus to avoid generating a giant number that slows everything to a crawl before the modulo is taken at the end.
Functions:
- a.pow(b, m) Computes a ^ b % m more quickly than using the power ^ and modulo % operators.
- a.inverse(m) Computes the multiplicative inverse of a modulo m.
- gcd(a, b) Computes the gcd of a and b.
- xgcd(a, b) Returns an array [g,x,y] where g is the gcd, and x and y are Bézout coefficients such that a*x + b*y = g
- sqrt(a, p) Computes the square root of a truncated to an integer. Or provide a prime p to get the square root in 𝔽p.
- isprime(a) Returns true/false telling if a is a prime number.
- random(a) Returns a random number a bytes long.
- factor(a) Returns an array containing the prime factors of a. (Slow for large numbers.)
- log(g, h, m) Computes the base g discrete log of h mod m, which is x such that g ^ x % m = h (Slow for large numbers.)
- ECurve(A, B, N) Creates an elliptic curve defined by Y2 = X3 + AX + B (mod N)
- c.point(x, y) Gets the point (x, y) on the elliptic curve c. (Leave y blank to derive it from x, or both blank to get 𝒪.)
- c.cardinality() Counts the number of points on the elliptic curve. (Slow for large N.)
- print(a) Prints a to the output log.
Examples: