Answer the question
In order to leave comments, you need to log in
How to encrypt and write a string to a file using Python?
Hello.
There is a code that, after the end of the game, should read a line from the file (record), compare it with the result of the player and write it to the file in encrypted form.
The code looks like this:
def write_record(self):
try:
self.record_file = open("../statistics/record.txt", "r")
except:
sys.exit()
for line in self.record_file:
print(line)
self.record = self.decryptor.decrypt(line.decode("hex"))
print(self.record)
self.record = self.record[0:len(self.record) / 16]
print(self.record)
if int(self.record) < self.fugitive.time_score:
self.record = self.fugitive.time_score
self.record_file.close()
try:
self.record_file = open("../statistics/record.txt", "w")
except:
sys.exit()
self.record = self.encryptor.encrypt(str(self.record) * 16)
self.record_file.write(self.record.encode("hex"))
self.record_file.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question