2626__version__ = "0.0.0-auto.0"
2727__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RSA.git"
2828
29+
2930def fast_pow (x , e , m ):
3031 """Performs fast modular exponentiation, saves RAM on small CPUs/micros.
3132 :param int x: Base
@@ -38,7 +39,7 @@ def fast_pow(x, e, m):
3839 while E > 0 :
3940 if E % 2 == 0 :
4041 X = (X * X ) % m
41- E = E // 2
42+ E = E // 2
4243 else :
4344 Y = (X * Y ) % m
4445 E = E - 1
@@ -50,33 +51,33 @@ def assert_int(var, name):
5051 if is_integer (var ):
5152 return
5253
53- raise TypeError (' %s should be an integer, not %s' % (name , var .__class__ ))
54+ raise TypeError (" %s should be an integer, not %s" % (name , var .__class__ ))
5455
5556
5657def encrypt_int (message , ekey , n ):
5758 """Encrypts a message using encryption key 'ekey', working modulo n"""
5859
59- assert_int (message , ' message' )
60- assert_int (ekey , ' ekey' )
61- assert_int (n , 'n' )
60+ assert_int (message , " message" )
61+ assert_int (ekey , " ekey" )
62+ assert_int (n , "n" )
6263
6364 if message < 0 :
64- raise ValueError (' Only non-negative numbers are supported' )
65+ raise ValueError (" Only non-negative numbers are supported" )
6566
6667 if message > n :
6768 raise OverflowError ("The message %i is too long for n=%i" % (message , n ))
6869
69- #return pow(message, ekey, n)
70- #print('fast_pow({},{},{})'.format(message,ekey,n))
70+ # return pow(message, ekey, n)
71+ # print('fast_pow({},{},{})'.format(message,ekey,n))
7172 return fast_pow (message , ekey , n )
7273
7374
7475def decrypt_int (cyphertext , dkey , n ):
7576 """Decrypts a cypher text using the decryption key 'dkey', working modulo n"""
7677
77- assert_int (cyphertext , ' cyphertext' )
78- assert_int (dkey , ' dkey' )
79- assert_int (n , 'n' )
78+ assert_int (cyphertext , " cyphertext" )
79+ assert_int (dkey , " dkey" )
80+ assert_int (n , "n" )
8081
8182 message = fast_pow (cyphertext , dkey , n )
8283 return message
0 commit comments