D
D
deleted-dazgalbag2015-07-02 20:48:52
Encryption
deleted-dazgalbag, 2015-07-02 20:48:52

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()

On first run output:
8eebc122fe1508e1eb4c6f2f9c8b0021
6666666666666666
6
On restart of game output:
8eebc122fe1508e1eb4c6f2f9c8b0021
#>zY6
Screenshot attached:
5e96e953bb1f414398939430691cc789.png
Why is this happening? How to fix

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question