Quote:
Originally Posted by Qonquer
Not dome much .NET stuff myself, just a little worried about the seeding of the PRNG like that. Are the variables used in srand() and rand() private to that particular thread or are they global for the entire application? If the latter is true, it could cause problems to a whole server application to have the seed constantly reset to a relatively small integer everytime someone logs on. A multi threaded application could also call rand() right in the middle of the key generation causing a failed login. Of course, if the routines are pure to the thread it isn't an issue.
|
Code:
public class rand
{
static int _seed;
int seed;
public rand(int seed)
{
this.seed = seed;
}
public final int _next()
{
seed *= 0x343fd;
seed += 0x269Ec3;
return (seed >> 0x10) & 0x7FFF;
}
public static void seed(int seed)
{
_seed = seed;
}
public static final int next()
{
_seed *= 0x343fd;
_seed += 0x269Ec3;
return (_seed >> 0x10) & 0x7FFF;
}
public static final int next(int max)
{
return (next() % (max + 1));
}
public static final int next(int min, int max)
{
return (next() % (int) (((max) + 1) - (min))) + (min);
}
}
could just do
rand rand = new rand(seed)
rand._next();
or static mode
rand.seed(seed)
rand.next()
That's in Java, basically a copy of what msvcrt does because Java's random sucks
edit: Also, I'm having some problems with my encryptions still, it decrypts correctly about half the letters (and all upper case). I think the mapping may be wrong, not sure (using sparkie's source).
For example:
Encrypted (by client): teest
Decrypted (by proxy): ( S( (contains 2 spaces after ( )
Encrypted (by client): aaabbb
Decrypted (by proxy): ���BBB