Unformatted text preview: somewhere in the neighborhood of 1018. If you only have a 16bit computer, use this generator instead: static int s1 = 1 ; /* An “int” must be 16 bits long. */ static int s2 = 1 ; static int s3 = 1 ; #define MODMULT(a,b,c,m,s) q = s/a; s = b*(sa*q)  c*q; if (s<0) s+=m ; /* combined LCG returns a pseudorandom real value in the range * (0,1). It combines linear congruential generators with * periods of 215405, 2151041, and 2151111, and has a period * that is the product of these three prime numbers. */ double combinedLCG ( void ) { int q ; int z ; MODMULT ( 206, 157, 21, 32363, s1 ) MODMULT ( 217, 146, 45, 31727, s2 ) MODMULT ( 222, 142, 133, 31657, s3 ) z = s1  s2 ; if ( z > 706 ) z = 32362 ; z += s3 ; if ( z < 1 ) z += 32362 ; return z * 3.0899e5 ; } /* In general, call initLCG before using combinedLCG. */ void initLCG ( int InitS1, int InitS2, InitS3 ) { s1 = InitS1 ; s2 = InitS2 ; s3 = InitS3 ; } This generator works as long as the machine can represent all integers between32363 and 32363. The variables, s1, s2, and s3, are global; they hold the current state of the generator. Before the first call, they must be initialized. The variable s1 needs an initial value between 1 and 32362. The variable s2 needs an initial value between 1 and 31726. The variable s3 needs an initial value between 1 and 31656. This generator has a period of 1.6*1013. For both of these generators, the constant term b in the linear congruence is 0. 16.2 Linear Feedback Shift Registers
Shift register sequences are used in both cryptography and coding theory. There is a wealth of theory about them; stream ciphers based on shift registers have been the workhorse of military cryptography since the beginnings of electronics. A feedback shift register is made up of two parts: a shift register and a feedback function (see Figure 16.1). The shift register is a sequence of bits. (The length of a shift register is figured in bits; if it is n bits long, it is called an nbit shift register.) Each time a bit is needed, all of the bits in the shift register are shifted 1 bit to the right. The new leftmost bit is computed as a function of the other bits in the register. The output of the shift register is 1 bit, often the least significant bit. The period of a shift register is the length of the output sequence before it starts repeating. Cryptographers have liked stream ciphers made up of shift registers: They are easily implemented in digital hardware. I will only touch...
View
Full Document
 Fall '10
 ALIULGER
 Cryptography, Bruce Schneier, Applied Cryptography, EarthWeb, Search Search Tips

Click to edit the document details