I’m following the RSA algorithm from the Wiki: http://en.wikipedia.org/wiki/RSA_(algorithm)
I am using Python 3.3.0 and I’m trying to do RSA Encryption and I ran into two problems that I don’t know how to do.
In the Encryptions class, my methods all need to be indented one level in to indicate that they are methods of the class and are not global functions.
When the main script asks for input at the end, if I just hit return, an exception is thrown that Python reached an unexpected EOF.
How can I do that ?
My code so far:
Modular.py
def _base_b_convert(n, b):
if b < 1 or n < 0:
raise ValueError("Invalid Argument")
q = n
a = []
while q != 0:
value = int(q % b)
a.append(value)
q =int(q / b)
return a
def mod_exp(base, n, mod):
if base < 0 or n < 0 or mod < 0:
raise ValueError("Invalid Argument")
a = (_base_b_convert(n, 2))
x = 1
pow = base % mod
for i in range(0, len(a)):
if a[i] == 1:
x = (x * pow) % mod
pow = pow**2 % mod
return x
main.py
from encryptions import Encryptions
def main():
enc = Encryptions()
message = enc.encrypt(message)
print(message)
print()
print("Decrypting message:")
message = enc.decrypt(message)
print(message)
input("--Press any key to end--")
if __name__ == '__main__':
main()
input()in Python 2 is not what you think it is — rather, it evaluates the string inputted as Python code, which is not what you want. Instead, useraw_input.As for your indentation problem, that’s just Python syntax. Nothing you can do.