I'm new with python and programming and all of that, but I have a project in which I use programming (because I'm interested in it :) )
In this project, my partner and I would like to have someone to input their message in the code (not in the python file ofcourse), after that, the message would get cyphered and you get the private and public keys (in RSA).
We are allowed to use work of others, as long as we explain why or how it works. I already have found a nice code about RSA, but it's missing a way of a user's input. The code can be found here: http://code.activestate.com/recipes/578797-public-key-encryption-rsa/.
Now I would like to ask: How can I change the message (in the code appearing as msg: ) to something where the user can input something?
I already tried using the input command, but that didnt seem to work.
After that, we would like the program to give the user their public and private key, which can be put back into the program to get the original text. We don't really know how we can write it like that, so we thought we should ask it!
Thanks in advance already :)
btw, we are using python 3.5!
You can just modify these lines (from your example):
def main():
import doctest
print(doctest.testmod())
pubkey, privkey = keygen(2 ** 64)
msg = u'the quick brown fox jumped over the lazy dog ® ⌀'
h = encode(msg, pubkey, True)
p = decode(h, privkey, True)
print('-' * 20)
print('message:', msg)
print('encoded:', b64encode(h).decode())
print('decoded:', p)
print('private key:', key_to_str(privkey))
print('public key:', key_to_str(pubkey))
To
def main():
import doctest
print(doctest.testmod())
pubkey, privkey = keygen(2 ** 64)
msg = input('Please type your message: ')
h = encode(msg, pubkey, True)
p = decode(h, privkey, True)
print('-' * 20)
print('message:', msg)
print('encoded:', b64encode(h).decode())
print('decoded:', p)
print('private key:', key_to_str(privkey))
print('public key:', key_to_str(pubkey))
Note you may have to use raw_input()
in python 2.x.