Here is my encryption program. The decryption program is what is giving me some trouble.
Here is the description of the first part:
# encrypt.py - ENCODE MESSAGE AND WRITE TO FILE
#
# initialize a cipher list to store the numeric value of each character
# input a string of text to encrypt
#
# for each character in the string:
# convert the character to its unicode value
# encode the unicode value into an integer with an encryption formula
# convert the encoded integer to a string
# append the encoded string to the cipher list
#
# for debugging purposes, print the cipher list - make sure data is correct
#
# open an output file to store the encrypted message
# write (print) the cipher list to the file
# close the file
def main():
cipher = []
#initialize string message
message = input("Please enter your message for encryption: ")
#loops through string message and encrypts
for ch in message:
x = ord(ch)
x = (2*x)-3
x = chr(x)
cipher.append(x)
#Print cipher from prompt
#print("Your code message is: ", cipher)
#open file for writing
outfile = open("Encryptedmessage.txt","w")
print (cipher, file=outfile)
main()
Here is the description of the second part:
# decrypt.py - DECODE MESSAGE FROM FILE AND DISPLAY
#
# initialize a message list to contain the decoded message
# open the input file containing the encrypted message
# read the line containing the message from the file into a string
# split the string into a cipher list of individual strings
#
# for each string in the cipher list:
# convert the string to an integer
# decode the integer into its unicode value using the decryption formula
# convert the unicode value to its corresponding character
# append the character to the message list
#
# print the message list
# close the file
Here is what I have for the decryption program:
def main():
deCipher = []
infile = open("Encryptedmessage.txt","r")
for ch in infile:
x = ord(ch)
x = (x/2)+3
x = chr(x)
deCipher.append(x)
print (deCipher)
main()
my logic in decrypting is going awry somewhere. I can't figure out how to make the contents of the file available to iterate through for decrytion.
Any hints and tips would be appreciated.
I accidentally posted this in community center as well.