Jul-21-2017, 08:37 PM
Hi guys! I'm learning python from Kenneth A Lambert's book, and I'm stuck in this exercise. The book asks me to write a script that crypts a message using ASCIIs. I wrote two scripts, one to crypt the message and the other to encrypt it, but they just don't seem to work, if I get a result from one, the other is going to give me a different one.
Script 1
Script 1
frase = input("Insert a text to crypt: ") dist = int(input("Insert distance: ")) code = "" for word in frase: value = ord(word) crypt = value + dist if codice > ord(chr(127)): codice = ord(chr(33)) + dist - (ord(chr(127)) - crypt) code += chr(crypt) print("Your crypted code is : ", code)Script 2
frase = input("Insert a text to decrypt it: ") dist = int(input("Insert distance: ")) code = "" for word in (frase): value = ord(word) crypt = value - dist if crypt < ord(chr(33)): crypt = ord(chr(127)) - (dist - (codice - ord(chr(33)))) code += chr(crypt) print("Your uncrypted message is: ", code)