Data and Math

vnumtheory

Primes, modular arithmetic and an RSA key pair generator meant only for teaching.

Released v1.0.0 · 2026-09-28
Import
use "stdlib/numtheory.ven"
vnumtheory.ven
print prime_factors(360)
Reference (10 functions)

API reference

prime_factors(n)

Gives back the prime factorization of n, smallest factor first.

prime_factors(360)

euler_totient(n)

euler_totient(360)

is_coprime(a, b)

is_coprime(17, 20)

generate_small_prime(min_value, max_value)

Picks a random prime between min_value and max_value, inclusive.

generate_small_prime(10, 50)

generate_rsa_keypair(bit_size_hint)

Generates a toy RSA keypair, (public_key, private_key), from a bit-size hint.

generate_rsa_keypair(16)

rsa_encrypt(public_key, message_int)

Encrypts message_int under public_key with textbook RSA.

rsa_encrypt((20687, 7), 42)

rsa_decrypt(private_key, ciphertext_int)

Decrypts ciphertext_int under private_key with textbook RSA.

rsa_decrypt((20687, 8743), 12580)

diffie_hellman_public_key(private_key, prime, generator)

Computes one side's Diffie-Hellman public key.

diffie_hellman_public_key(6, 23, 5)

diffie_hellman_shared_secret(private_key, other_public_key, prime, generator)

Computes the shared secret from one side's own private key and the other side's public key.

diffie_hellman_shared_secret(15, 8, 23, 5)

chinese_remainder(remainders, moduli)

Solves a system of congruences with the Chinese Remainder Theorem.

chinese_remainder([2, 3, 2], [3, 5, 7])

Get notified when vnumtheory changes

Get notified about

New versions and security advisories.

New and updated packages, once a day.

News on the math model built in Venutian.