2025-06-24 16:42:17 +10:00
|
|
|
The "imbaud python library" (imp lib), or just imp for short!
|
2025-07-01 23:23:23 +10:00
|
|
|
|
|
|
|
|
TODO:
|
|
|
|
|
- define a getPrime function like PyCryptodome's
|
2025-07-06 19:20:20 +10:00
|
|
|
- rewrite nim-lang/bigints to implement features like Karatsuba multiplication, or even Toom-3 multiplication
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PyCryptodome defines getPrime as follows:
|
|
|
|
|
```py
|
|
|
|
|
def getPrime(N, randfunc=None):
|
|
|
|
|
"""Return a random N-bit prime number.
|
|
|
|
|
|
|
|
|
|
N must be an integer larger than 1.
|
|
|
|
|
If randfunc is omitted, then :meth:`Random.get_random_bytes` is used.
|
|
|
|
|
"""
|
|
|
|
|
if randfunc is None:
|
|
|
|
|
randfunc = Random.get_random_bytes
|
|
|
|
|
|
|
|
|
|
if N < 2:
|
|
|
|
|
raise ValueError("N must be larger than 1")
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
number = getRandomNBitInteger(N, randfunc) | 1
|
|
|
|
|
if isPrime(number, randfunc=randfunc):
|
|
|
|
|
break
|
|
|
|
|
return number
|
|
|
|
|
```
|
|
|
|
|
in essence infinite random generation until a prime is found
|