applied cryptography - protocols, algorithms, and source code in c

0 119 8 0 24 4 3 1 0 55 6 2 1 0 87 13 0

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: somewhere in the neighborhood of 1018. If you only have a 16-bit 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*(s-a*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 215-405, 215-1041, and 215-1111, 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.0899e-5 ; } /* 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 between-32363 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 n-bit 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 left-most 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

This note was uploaded on 10/18/2010 for the course MATH CS 301 taught by Professor Aliulger during the Fall '10 term at Koç University.

Ask a homework question - tutors are online