0

This may be a weird question but I am wondering if there is any encoding system that results in integer's only. My goal is to encode a numerical score from a game into something that looks like a score but isn't. And yes I know if you spent another 5 seconds you could probably figure out what's going on. But I want to prevent people from changing the score variable from 500 to 99999. I want to make it at least slightly harder.

So TLDR - I want to know if there is a way to take say 500 and turn it into 8346634894 that could then be turned back into 500.

Bonus points if it can somehow maintain order (so 500 would be less "value wise" then 600 and so on).

Any ideas?

10
  • 1
    Do a base conversion. Or multiply by some value, then divide again. Or do anything at all. It really hardly makes any difference, since anybody will be able to inspect the source code to see what exactly it is you're doing anyway. Commented May 26, 2014 at 12:42
  • take a look at Math functions in Javascript, maybe it could help w3schools.com/jsref/jsref_obj_math.asp Commented May 26, 2014 at 12:42
  • @deceze the point is not to prevent that. It's to make it slightly harder then typing in score = 99999 in console and getting a new score. The script is compressed down and there is a fair amount of them. It would take the effort from 5 seconds to at least 15 minutes. That's all I want. Commented May 26, 2014 at 12:44
  • @deceze It would make a difference in so far that it would not just be a simple value change, but require somebody to really look at the source code. Commented May 26, 2014 at 12:45
  • rot13! Or in the case of numbers, it'd probably be rot5. Commented May 26, 2014 at 12:45

1 Answer 1

1

You could try implementing a numeric variant on "amazingly safe" rot13 algorithm: rot5.

A score of 1337 would be translated to 6882, and the "beauty" of the cipher is that it is its own inverse, meaning you can just apply it again to decode your encrypted scores!

A simple implementation could be:

function rot5(score){
    var list = '5678901234'.split('');
    return (score+"").split('').map(function(e){return list[e]}).join('');
}

Note that this does return strings, as the result could start with a 0. If you want to decode the encrypted number, you can do that like this:

decrypted = parseInt(rot5(encrypted), 10);
Sign up to request clarification or add additional context in comments.

1 Comment

So, @Steven, is this what you want?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.