sophiegermain module
Pure-Python library that provides a selection of Sophie Germain primes that are organized by representation size.
- sophiegermain.sophiegermain.sophiegermain(bit_length: int) int[source]
Return the smallest Sophie Germain prime the representation of which requires the specified number of bits.
>>> sophiegermain(2) 2 >>> sophiegermain(8) 131 >>> sophiegermain(16) 32771 >>> sophiegermain(32) 2147483693 >>> sophiegermain(257) 115792089237316195423570985008687907853269984665640564039457584007913129658411 >>> sophiegermain(1025).bit_length() 1025
The result returned by
sophiegermaincan be represented using the specified number of bits.>>> all([sophiegermain(k).bit_length() == k for k in range(2, 1026)]) True
If a bit length outside the supported range is supplied, an exception is raised.
>>> sophiegermain(-1) Traceback (most recent call last): ... ValueError: all Sophie Germain primes have bit lengths of at least 2 >>> sophiegermain(1) Traceback (most recent call last): ... ValueError: all Sophie Germain primes have bit lengths of at least 2 >>> sophiegermain(1026) Traceback (most recent call last): ... ValueError: bit lengths greater than 1025 are not supported
The supplied bit length must be an integer.
>>> sophiegermain('abc') Traceback (most recent call last): ... TypeError: bit length must be an integer