MD5 encryption | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

MD5 encryption

I've coded a program to create a MD5. You can see the code in my library. I would love to know if someone of you can tell me how to make it working in "Python 3". It was coded in "Python 2.7". One error I've seen is that "print" requires () in python3. But my main concern is on the "hashlib.md5" library. Hope someone of you can help me. Thanks

4th Mar 2017, 9:58 PM
Gabri
4 Answers
+ 10
About changes from 2 to 3 in "print": - require ( ) as it's now a function, no more a statement - raw_input is becomes unecessary with 3 About adaptation of md5 use: - just change type of parameter from unicode to Python root byte string: import hashlib import time from random import randint salt= randint(0,99999999) loop=3 while loop==3: key_string = input( "Key to turn into an MD5 password? " ) print(key_string) print( hashlib.md5(key_string.encode("utf-8")).hexdigest()) time.sleep(1.5) option= input("Would you like to salt it? (Y/N)").lower() if option == 'y': hash = hashlib.md5( (str(salt) + key_string).encode("utf-8")).hexdigest() print("%s:%s" % (salt, hash) ) time.sleep(1) options=input("Would you like to encrypt another hash? (Y/N)").lower() if options=='y': loop=3 if options=='n': loop=0 if option == 'n': options=input("Would you like to encrypt another hash? (Y/N)").lower() if options=='y': loop=3 if options=='n': loop=0 if loop==0: print("Ok,bye!") time.sleep(2) exit
6th Mar 2017, 8:26 AM
visph
visph - avatar
+ 9
User inputs are handled in a special way at sololearn code playground: you need to put all the entries needed by your script at once, just after start running, each separated on a new line ( but single entry )... in example: Text to encode y n
6th Mar 2017, 10:19 AM
visph
visph - avatar
0
thank you very much for your reply! I've made the changes, but now it give me: eoferror: error when reading a line", referring to line 30. I'll try to find a solution soon!
6th Mar 2017, 9:47 AM
Gabri
0
thanks again for your help!!
6th Mar 2017, 10:29 AM
Gabri