I am able to encrypt the file but when I decrypt it goes into a loop creating a mass file increasing size second by second with no decryption.
if choice == 3:
string_input = input("Please enter name of file to encrypt: ")
input_offset = int(input("Please enter offset value (1 to 96): "))
encrypted = ""
orig_file = open('C:\\Users\\message.txt', 'r')
encrypted_file = open('new_msg.txt','w')
file_read = orig_file.read()
for file in file_read:
x = ord(file)
encrypted += chr(x + input_offset)
encrypted_file.write(str(x) + " ")
encrypted_file.write(str(encrypted))
while x < 32:
x += 96
while x > 126:
x -+ 96
orig_file.close()
encrypted_file.close()
print("Encrypt successful. Encrypted text written to file: new_msg.txt")
if choice == 4:
string_input = input("Please enter name of file to decrypt: ")
input_offset = int(input("Please enter offset value (1 to 96): "))
decrypted = ""
enc_open_file = open('new_msg.txt', 'r')
decrypted_file = open('orig_msg.txt','w')
enc_file_read = enc_open_file.read()
for file in enc_file_read:
x =ord(file)
decrypted += chr(x - input_offset)
decrypted_file.write(str(x) + " ")
decrypted_file.write(str(decrypted))
while x < 32:
x += 96
while x > 126:
x -+ 96
enc_open_file.close()
decrypted_file.close()
print("Decrypt successful. Decrypted text written to file: orig_msg.txt")