Algorithm Help

Started by
13 comments, last by Firestryke31 12 years, 9 months ago
I was thinking of using the elements I was talking about as said seed. Since I decided not to involve them in the shuffle I can reconstruct the seed client-side to replay the shuffle in reverse.

I wanted to minimize the amount of data transmitted, so why not make it so that the only data transmitted is the data I need to transmit, rather than tacking on some data that's only used for one step in the process? The data I'm using to seed the shuffle are checksum and parity, so they're there to validate the data anyway, why not use them for something else as well?

Also, I didn't want to rely on an outside PRNG since it's implementation might change between compilers, making data generated by a version of the program compiled by one compiler unreadable to a version compiled by another. The only way around this is to write my own PRNG or use one online (and deal with the licensing stuff), and I want to write games, not random number generators.

Finally, it doesn't even have to be random, it just has use different steps to shuffle dataset 1 and dataset 2.
Advertisement
If you want a PRNG with a very free license (do what you want with it), I posted some code here.
I just went with something simplistic:

Shuffle:

char s = 0;
int j = 0;
unsigned short seed = data[0] | (data[9] << 8);
for(int i = 0; i < 8; ++i)
{
j = seed % 8;
seed /= 5;
seed *= j + 1;
s = data[i + 1];
data[i + 1] = data[j + 1];
data[j + 1] = s;
}


Unshuffle:

char unsh[] = {0,0,0,0,0,0,0,0,0,0};
char s = 0;
int j = 0;
unsigned short seed = data[0] | (data[9] << 8);
for(int i = 0; i < 8; ++i)
{
j = seed % 8;
seed /= 5;
seed *= j + 1;
unsh[i + 1] = j;
}

for(int i = 8; i > 0; --i)
{
s = data;
data = data[unsh + 1];
data[unsh + 1] = s;
}


I don't know how expandable it is, but it gets the job done here and I can implement something similar if I need a bigger version.
Is this just a crude encryption of some sort? If so why not use something like XTEA or something similar. If not, my bad, but it does look like you're just trying to obfuscate some data.
Honestly, it is. It's just a simple way to keep sequential input from being sequential output. I just needed something simple and easy to write that doesn't really have to be all that secure, just enough to keep everybody and their mom from being able to easily figure out the next value without going through my code first.

I know it'll be broken within 10 minutes of some bored guy pointing his interest in my general direction, so why bother spending more than 10 minutes writing it? Had I known about XTEA before finishing my code, I would have used it instead of rolling my own. I'll probably end up using it on my network traffic.

This topic is closed to new replies.

Advertisement