|
This thread is locked; no one can reply to it. |
1
2
|
Saving game status using primes |
Johan Halmén
Member #1,550
September 2001
|
Thought I'd share this. I had the idea of saving game status using primes. I have this game where the played level number is saved in a cfg (or ini) file. The task is to convert a level number, say 1 - 10, to a coded number and save it. Then, at next app launch, read the number and decode it. The coding thing goes as follows. Numbers 1 to 10 correspond to 51st to 60th prime numbers. F.i. if I code number 3, I pick the 53rd prime number. Then I repeatedly multiply the number with random numbers below the 51st prime number until I get an integer overflow. The previous product before the overflow is my coded number. To decode it, I factorize the number and check which is the highest prime factor. I compare it with primes #51 - #60. This system could hold more than one number. Say primes #31 to #40 would mean level number, #41 to #50 bonus status, #51 to #60 would mean lives left. Multiply them together, then repeatedly multiply with random numbers below the 31st prime. And after factorizing, you will find your three primes telling you the status of the game. Of course this is not fool proof. I just happen to like primes and it was fun to implement a class for this. And I needed an easy way to store game status in a text file like a cfg file, to be able to edit the status by hand for testing purposes. I could easily switch to a binary file, when creating a release version of the game, just to make it a bit harder to crack, but I guess I won't bother. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
J-Gamer
Member #12,491
January 2011
|
I think you should make it pick numbers from 1 to the 31th prime * 2 - 1 It could make the encryption faster because overflow would be reached faster ^^ " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
weapon_S
Member #7,859
October 2006
|
Good job reinventing the wheel Personally I'm also fascinated by this sort of principles. But the math involved is like voodoo to me. IIRC prime factorization is a very slow procedure. (Dividing by ten numbers isn't ) |
Neil Walker
Member #210
April 2000
|
In my game I just gave each level a random name and stored that in plain text in the config file and cross-checked against an array in code. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
OnlineCop
Member #7,919
October 2006
|
1<?xml>
2<configuration>
3 <comment>Don't edit this file... you'll only be hurting yourself.</comment>
4 <levels>
5 <level>
6 <highscore>10</highscore>
7 <beat_level>TRUE</beat_level>
8 </level>
9 <level>
10 <highscore>3</highscore>
11 <beat_level>FALSE</beat_level>
12 </level>
13 ...
14 </level>
15</configuration>
|
Mark Oates
Member #1,146
March 2001
|
Just rot13. That'll stop 80% of 'em. @OnlineCop -- |
Oscar Giner
Member #2,207
April 2002
|
Now that you've made public how the encryption works, it's become useless (which is a bad think since it means your encryption relies on not knowing the algorithm used). -- |
Johan Halmén
Member #1,550
September 2001
|
But it gives more value to the gaming. They still have to figure out how to do the factorising. And they still have to figure out what primes correspond to what thing. If they succeed, I guess I've made them even more happy. My settings.ini file said: status = 244863114 Ok, if I rot13 it: fgnghf = 244863114 Um, I guess I could as well just use that name from the start and not perform the actual rot13 thing at any point. Special Christmas cookies to the first one to figure out which level number is hidden in the number above. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
J-Gamer
Member #12,491
January 2011
|
The highest prime factor of that number is 137, which is the 33rd prime number. So I guess it codes the 3rd level :p " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
Oscar Giner
Member #2,207
April 2002
|
Johan Halmén said: They still have to figure out how to do the factorising. Open Mathematica and type FactorInteger[n] . With such small numbers the result is instantaneous. -- |
BAF
Member #2,981
December 2002
|
Quote: Just rot13. That'll stop 80% of 'em. Even better would be to use rot26. Wouldn't that stop like 160% of them or something? |
SiegeLord
Member #7,827
October 2006
|
Oscar Giner said: Open Mathematica and type FactorInteger[n] . With such small numbers the result is instantaneous. Or: $ factor 244863114 244863114: 2 3 37 83 97 137 Installed by default on every GNU/Linux operating system . "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Johan Halmén
Member #1,550
September 2001
|
See, even if I told you this much, no one has figured out the right answer. Just in case someone would like to figure it out, I won't reveal it yet. But the real situation is of course that you know what level you are on when you quit the game. And you want to cheat by creating the secret number corresponding to a higher level and writing it by hand in the settings.ini file. So if you find the number 244863114 in the file, you have solved level 8 in the game. What number could you write there so that the program believes you have solved level 9 and lets you play level 10? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Matthew Leverton
Supreme Loser
January 1999
|
139 because you have 13 * 10 + 9. Edit: A serious reply. The drawbacks are:
Now of course #2 is made more difficult without prior knowledge, but if you are looking for patterns in a number, it would make sense to look at its factors. |
Neil Walker
Member #210
April 2000
|
How about something simple like add a mod 7 check digit to the end to decrease the chance of stumbling across a random prime then? e.g. 179 becomes 1794. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Mark Oates
Member #1,146
March 2001
|
BAF said: Even better would be to use rot26. Wouldn't that stop like 160% of them or something?
-- |
Oscar Giner
Member #2,207
April 2002
|
Johan Halmén said: So if you find the number 244863114 in the file, you have solved level 8 in the game. What number could you write there so that the program believes you have solved level 9 and lets you play level 10? In a real world situation I wouldn't have only the number for level 8, but also the number for previous levels. -- |
Karadoc ~~
Member #2,749
September 2002
|
I think that once the player know that the factors store the information, it would not be hard to work out which factors are important -- but I don't think anyone would get that far in the first place unless it was really important for some reason. Playing the game itself is probably easier and more fun than trying to decode the save files. ----------- |
weapon_S
Member #7,859
October 2006
|
Very true. Johan Halmén said: Um, I guess I could as well just use that name from the start and not perform the actual rot13 thing at any point. If you re-encode each variable at each save, that might be a pretty good deterrent for the average cheater. (Given that the stored variables change a lot.) To crack that, you'd have to fill in a random number, until it is valid, and then see which value in-game has changed. BAF said: Even better would be to use rot26. Wouldn't that stop like 160% of them or something? No, you'd stop 60% from being stopped; thus only stopping 40%. |
Johan Halmén
Member #1,550
September 2001
|
Karadoc ~~ said: Playing the game itself is probably easier and more fun than trying to decode the save files. My point. If that is true, I've provided some fun. If the decoding is more fun than the game itself, I've provided some fun. The third option is that neither is fun. Here are possible numbers for previous levels: 1 52405870 2 715183693 3 33987587 4 166937969 5 48161165 6 28905073 7 81948229 8 94781258 9 99191095 10 47991559 Here's another list: 1 30965590 2 22503131 3 778272953 4 51739793 5 25087921 6 41662858 7 55675786 8 282614834 9 231828509 10 77419357 Guess it's obvious now - if anyone bothers at all. The game I used this in is my SantaHack entry, found in the Depot forum. Matthew Leverton said: I can pick any large number and if it has some expected prime numbers as a factor, then it's valid. But if 139 is one prime factor that has to be there, you have one chance of 139 to pick right. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Gideon Weems
Member #3,925
October 2003
|
Johan Halmén
Member #1,550
September 2001
|
It shows that my system works. There's not enough fun involved to solve it. And still I believe it's not too hard for you to solve, say you get thrilled by the game but can finish only so many levels. If that's what it gets to make you solve my codec, then you are happy and I am happy. Gideon Weems said: If you're looking to provide some real fun, you should consider making your save states as easily editable as possible Editing with Notepad is the way to go. If I provide a GUI inside the game for this, I kind of give it away that it is meant to be hacked. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Matthew Leverton
Supreme Loser
January 1999
|
Johan Halmén said: It shows that my system works. There's not enough fun involved to solve it. What are we supposed to be solving? It's obvious that the highest prime factor starts at 101 for level one, and then increases for every level. |
Johan Halmén
Member #1,550
September 2001
|
Um... yes, simple as that. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
William Labbett
Member #4,486
March 2004
|
If you really want to make you stuff secure join GIMPS and starting looking for new Mersenne prime's and make sure to not tell them if you find a Mersenne prime. If by a large miracle you find one, use that and any other one in that form of encryption that uses two primes to encrpyt everything. Not sure if that's even legal :/ (if not I don't recommend it as I don't want to be prosecuted). It'd work but it's probably the most inpractical advice can get though.
|
|
1
2
|