{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

# 70 atampt telephone security device tsd 3600users

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ctl, r1); r2 = clock_r2(clock_ctl, r2); r3 = clock_r3(clock_ctl, r3); bit = ((r1 >> 18) ^ (r2 >> 21) ^ (r3 >> 22)) & 0×01; byte = (byte << 1) | bit; bits++; if (bits == 8) { *ptr = byte; ptr++; bits = 0; byte = 0; } } if (bits) *ptr = byte; /* Run shift registers for another 100 bits to hide relationship between * Alice–>Bob key stream and Bob–>Alice key stream. */ for (i=0;i<100;i++) { clock_ctl = threshold(r1, r2, r2); r1 = clock_r1(clock_ctl, r1); r2 = clock_r2(clock_ctl, r2); r3 = clock_r3(clock_ctl, r3); } /* Produce 114 bits of Bob–>Alice key stream */ ptr = bob; bits = 0; byte = 0; for (i=0;i<114;i++) { clock_ctl = threshold(r1, r2, r2); r1 = clock_r1(clock_ctl, r1); r2 = clock_r2(clock_ctl, r2); r3 = clock_r3(clock_ctl, r3); bit = ((r1 >> 18) ^ (r2 >> 21) ^ (r3 >> 22)) & 0×01; byte = (byte << 1) | bit; bits++; if (bits == 8) { *ptr = byte; ptr++; bits = 0; byte = 0; } } if (bits) *ptr = byte; return (0); } void a5_key(a5_ctx *c, char *k){ c–>r1 = k[0]<<11|k[1]<<3 | k[2]>>5 ; /* 19 */ c–>r2 = k[2]<<17|k[3]<<9 | k[4]<<1 | k[5]>>7; /* 22 */ c–>r3 = k[5]<<15|k[6]<<8 | k[7] ; /* 23 */ } /* Step one bit in A5, return 0 or 1 as output bit. */ int a5_step(a5_ctx *c){ int control; control = threshold(c–>r1,c–>r2,c–>r3); c–>r1 = clock_r1(control,c–>r1); c–>r2 = clock_r2(control,c–>r2); c–>r3 = clock_r3(control,c–>r3); return( (c–>r1^c–>r2^c–>r3)&amp1); } /* Encrypts a buffer of len bytes. */ void a5_encrypt(a5_ctx *c, char *data, int len){ int i,j; char t; for(i=0;i<len;i++){ for(j=0;j<8;j++) t = t<<1 | a5_step(c); data[i]^=t; } } void a5_decrypt(a5_ctx *c, char *data, int len){ a5_encrypt(c,data,len); } void main(void){ a5_ctx c; char data[100]; char key = {1,2,3,4,5,6,7,8}; int i,flag; for(i=0;i<100;i++) data[i] = i; a5_key(&ampc,key); a5_encrypt(&ampc,data,100); a5_key(&ampc,key); a5_decrypt(&...
View Full Document

{[ snackBarMessage ]}