Log in

View Full Version : linear congruential generators & you


r00t
03-14-2014, 06:17 PM
the standard gcc library definition for rand() is a simple linear congruential generator

static unsigned long int next = 1;

int rand(void) // RAND_MAX assumed to be 32767
{
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}

void srand(unsigned int seed)
{
next = seed;
}

Linear congruential generator should also not be used for cryptographic applications; see cryptographically secure pseudo-random number generator for more suitable generators. If a linear congruential generator is seeded with a character and then iterated once, the result is a simple classical cipher called an affine cipher; this cipher is easily broken by standard frequency analysis.

if you think the embedded devices like your router or printer et al. is using anything fancier you are sadly mistaken

these are your x.509 certificates we're talking about here people

Weyoun the Vorta
03-14-2014, 06:18 PM
Shut up

Daldolma
03-14-2014, 06:19 PM
wat about ayn though

SamwiseRed
03-14-2014, 06:21 PM
im going back to school for computer science, maybe ill understand wtf this is all about soon.

maybe not.

r00t
03-14-2014, 06:21 PM
when your "random" number generator uses 12345 as a magic constant..... you "might" have a security vulnerability

http://www.jefffoxworthy.com/uploads/timeline/_homepage/jeff-foxworthy-timeline-2.png

r00t
03-14-2014, 06:23 PM
Let me see if I can put this in a way ya'll can understand. Studying the ramifications of this mathematical function is justification for ninalooting if you lose a /random

Weyoun the Vorta
03-14-2014, 06:25 PM
Ninalooting you say.

quido
03-14-2014, 06:31 PM
http://en.wikipedia.org/wiki/Mersenne_twister

r00t
03-15-2014, 09:05 PM
I implemented mersenne twister in pure C


static const unsigned int MT_STATE_SIZE = 624;

static unsigned int mt_state[MT_STATE_SIZE] = { 0 };
static unsigned int mt_index = 0;

static const unsigned int SEED_CONST = 0x6c078965;
static const unsigned int EXTRACT1_CONST = 0x9d2c5680;
static const unsigned int EXTRACT2_CONST = 0xefc60000;
static const unsigned int GENERATE_CONST = 0x9908b0df;

unsigned int mt_rand()
{
if (mt_index == 0)
{
for (int i = 0; i < MT_STATE_SIZE; ++i)
{
unsigned int y = (mt_state[i] & 0x80000000)
+ (mt_state[(i + 1) % MT_STATE_SIZE && 0x7fffffff]);

mt_state[i] = mt_state[(i + 397) % MT_STATE_SIZE] ^ (y >> 1);

if (y % 2 != 0)
mt_state[i] ^= GENERATE_CONST;
}
}

int y = mt_state[mt_index];

y ^= (y >> 11);
y ^= (y << 7) & EXTRACT1_CONST;
y ^= (y << 15) & EXTRACT2_CONST;
y ^= (y >> 18);

++mt_index;
mt_index %= MT_STATE_SIZE;

return y;
}

void seed_mt_rand(int seed)
{
mt_index = 0;
mt_state[0] = seed;

for (unsigned int i = 1; i < MT_STATE_SIZE; ++i)
mt_state[i] = (SEED_CONST * (mt_state[i - 1] ^ (mt_state[i - 1] >> 30)) + i)) & 0xFFFFFFFF;
}

by freely releasing this code I could possibly be breaking a non-compete agreement so yw

Doors
03-15-2014, 09:14 PM
?

Weyoun the Vorta
03-15-2014, 09:19 PM
Shut up

khanable
03-15-2014, 09:35 PM
did you just post this on stack overflow asking if it's correct because you're not sure?

r00t
03-15-2014, 09:43 PM
ya was 2 lazy to test it against the C++ 11 implementation

r00t
03-15-2014, 09:47 PM
Id say stackoverflow has ghostwritten 95% of the code I've published

I just compartmentalize the problem set, have them write the individual functions, then copy paste the snippets into my class or w/e it is Im doing

I've been banned about 30 times

khanable
03-15-2014, 09:48 PM
HOW AM I SUPPOSED TO BELIEVE YOU IF YOU'RE NOT EVEN SURE

r00t
03-15-2014, 09:56 PM
I'm thinking about writing a bitcoin miner for the browser using WebGL shaders. Think about it. Embed that shit on a high traffic website & you're utilizing the power of other peoples computers for as long as they stay on the page

I'm gonna be rich just sellin licenses of this shit 2 ppl

dre
03-15-2014, 09:59 PM
I'm thinking about writing a bitcoin miner for the browser using WebGL shaders. Think about it. Embed that shit on a high traffic website & you're utilizing the power of other peoples computers for as long as they stay on the page

I'm gonna be rich just sellin licenses of this shit 2 ppl

genius

BitcoinBrowser

khanable
03-15-2014, 10:00 PM
You'll be neck deep in internet vagina, for sure.

a_gnoll_pup
03-16-2014, 04:06 AM
>rand()
>2014

radditsu
03-16-2014, 09:55 AM
Who dares to care?

r00t
03-16-2014, 12:09 PM
>rand()
>2014

https://github.com/EQEmu/Server/search?q=rand%28%29&ref=cmdform

element08
03-16-2014, 03:22 PM
so how do i use this to always get a pet named Laser

radditsu
03-16-2014, 03:51 PM
How does this allow me to post cat pictures?