0
$\begingroup$

I am currently making a Python game where the user's high score gets encrypted and stored in a log (a text file). The reason for this encryption is because I don't want the user to be able to enter something (say, 1000000) into the text file. Is there a function that, given a string, will generate a string that looks random to the user (but it's not), and unlike a hash function, can be reversible? Does anyone know how to make one of these in Python? Thanks!

$\endgroup$
  • 3
    $\begingroup$ Why not encryption? $\endgroup$ – kelalaka May 6 at 0:32
  • 5
    $\begingroup$ Even just authentication without encryption seems to serve the purpose of preventing modification. $\endgroup$ – Maeher May 6 at 6:45
1
$\begingroup$

While not reversible, HMAC seem to be a plausible solution.

HMAC is a construct that adds a "key" to the hash digest, your program generates it with a symmetric key that's somewhat hidden in your program. You verify the player's scores by hashing the score with the key and compare the digest - this is a very typical tag comparison of message authentication code.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.