Jabutosama
Jabutosama

Reputation: 443

Obfuscating data before storing it

I have been using python since last summer and i think that i have absorbed enough information to do at least basic programming.

The thing is that i'm making text-based rpg-game and i have already done the saving process and the game now transfers information to savegame.txt. But i want to make game hacking harder. I saw in forums that changing file name is possible, but it wasn't close enough this case and/or i weren't able to read through lines how it works. So the idea is that it becomes unreadable format, but code inside won't change and it can be 'normalized' back.

so more clearly:

How do I change savegame.txt to savegame.xsave (or something like that) and vice versa?

Upvotes: 0

Views: 504

Answers (3)

Ben Fulton
Ben Fulton

Reputation: 3998

I agree with the comments that this probably isn't the best use of your time. But the simplest thing to do would be to take advantage of the rot13 encoder.

with open("data.secret", 'w') as f:
  f.write("player score: 500".encode('rot13'))
  f.write("player badge: cool guy".encode('rot13')

with open("data.secret") as f:
  x = f.readline().decode('rot13')

Upvotes: 1

CrouZ
CrouZ

Reputation: 1781

If you just want to make the text file unreadable you could just encode it with, for example, base64:

import base64
encoded = base64.b64encode("myTextFileContents")
decoded = base64.b64decode(encoded)

You can read more here: https://docs.python.org/3/library/base64.html

Upvotes: 0

Zav
Zav

Reputation: 661

Just encrypt all text in file with any encryption algorithm. For example, you can pycrypto library.

Upvotes: 0

Related Questions