Chop a large integer m into integer packets, where each packet has at most n digits
Example:
>>> chop_integer(123451234512345,5)
[12345, 12345, 12345]
Chop message m it into packets of at most n characters
Example:
>>> chop_message("This is a not so long message!",10)
['This is a ', 'not so lon', 'g message!']
Davis table decoding (from numbers to letters)
see http://mathcircle.berkeley.edu/BMC3/crypto.pdf
Example:
>>> davis_dec(184148485170)
'Hello!'
Davis table encoding (from letters to numbers)
see http://mathcircle.berkeley.edu/BMC3/crypto.pdf
Example:
>>> davis_enc("Hello!")
184148485170
Decode a list of integer packets into a message (using Davis table, see davis_dec())
Example:
>>> print decode_message([30444555104555103710L, 50515610555110485150L, 43104941555537434170L])
This is a
not so lon
g message!
Carries out extended Euclid’s algorithm on a and b.
Example:
>>> egcd(880,560)
(80, 2, -3)
Encode message m with packets of at most 2 n digits integers (using Davis table, see davis_enc())
Example:
>>> encode_message("This is a not so long message!",10)
[30444555104555103710L, 50515610555110485150L, 43104941555537434170L]
Miller-Rabin primality test.
A return value of False means n is certainly not prime. A return value of True means n is very likely a prime.
This code comes from: http://rosettacode.org/wiki/Miller-Rabin_primality_test#Python (with corrections!)
Example:
>>> is_probable_prime(50800665469)
True
>>> is_probable_prime(2**1279 -1)
True
Joins a large integer that has been chopped in a list
Example:
>>> join_integer([1234567,8910111213,141516171819])
12345678910111213141516171819L
Computes the multiplicative inverse of a modulo n. For the multiplcative inverse to exist, we must have \(\text{gcd}(a,n)=1\)
Example:
>>> modinv(17,880)
673
Generate a prime number with ndigits digits
Example:
>>> randprime(10)
50800665469
Do some checks on some RSA numbers. The numbers p,q,N,N2,e,d could come from rsa_gen()
Example:
>>> status,msg = rsa_check(23,41,943,880,17,503,1)
>>> print str(status)+" "+msg
False The following diagnostics failed:
e and d are not multiplicative inverses of each other
problem in enc/dec
>>> status,msg = rsa_check(23,41,943,880,17,673,1)
>>> print str(status)+" "+msg
True All tests passed!
N has 3 digits
N2 has 3 digits