How to take n in Python file manipulation

Asked

Viewed 283 times

0

I have to create a certain kind of encryption. I read a String and it is converted into ASCII and then written to a txt then in another code I read this txt with the encrypted string to be able to decrypt it. Each letter would be in a row only for this it is necessary to use the n. At the time of reading the encrypted string the n comes together. Can you take it? 'Cause I need the whole to run the decryption account.

Code to Encrypt string_1 = 'Gabriel do Prado de Oliveira'

 arq = open('cripto.txt', 'a')
 arq.write('\n')


for i in range(len(string_1)):
    cripto = ord(string_1[i])

    cripto = (cripto * 15) / 5

    arq.write(str(cripto))
    arq.write('\n')

Arq.close()

Code to Decrypt

arq = open('cripto.txt', 'r')
string_2 = ''
for i in arq:
    aux = (arq.read())
    aux = int(aux)
    final = int((aux / 15) * 5)
    string_2 += chr(final)

arq.close()
print(string_2)

1 answer

1

Use the strip. ex: string_2.strip().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.