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

# 0x2ba9c55d 0x741831f6 0x7a325381 0x28958677 0x61d809cc

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: ask to next bit */ short mult8(a, b, gen) short a, b; /* operands for multiply */ short gen; /* irreducible polynomial generating Galois Field */ { short product = 0; /* result of multiplication */ while(b != 0) { if (b & 01) product ^= a; a <<= 1; if (a >= SIZE) a ^= gen; b >>= 1; } return(product); } /* while multiplier is non–zero */ /* add multiplicand if LSB of b set */ shift multiplicand one place */ and modulo reduce if needed */ shift multiplier one place */ /* /* /* short exp8(base, exponent, gen) short base; /* base of exponentiation */ short exponent; /* exponent */ short gen; /* irreducible polynomial generating Galois Field */ { short accum = base; /* superincreasing sequence of base */ short result = 1; /* result of exponentiation */ if (base == 0) return(0); /* if zero base specified then /* the result is “0” if base = 0 */ */ while (exponent != 0) { /* repeat while exponent non–zero */ if (( exponent & 0×0001) == 0×0001) /* multiply if exp 1 */ result = mult8(result, accum, gen); exponent >>= 1; /* shift exponent to next digit */ accum = mult8(accum, accum, gen); /* & square */ } return(result); } void loki_key(loki_ctx *c, unsigned char *key){ setlokikey(c,key); } void loki_enc(loki_ctx *c, unsigned char *data, int blocks){ unsigned char *cp; int i; cp = data; for(i=0;i<blocks;i++){ enloki(c,cp); cp+=8; } } void loki_dec(loki_ctx *c, unsigned char *data, int blocks){ unsigned char *cp; int i; cp = data; for(i=0;i<blocks;i++){ deloki(c,cp); cp+=8; } } void main(void){ loki_ctx unsigned unsigned unsigned int i; lc; long data[10]; char *cp; char key = {0,1,2,3,4,5,6,7}; for(i=0;i<10;i++) data[i]=i; loki_key(&amplc,key); cp = (char *)data; loki_enc(&amplc,cp,5); for(i=0;i<10;i+=2) printf(“Block %01d = %08lx %08lx\n”, i/2,data[i],data[i+1]); loki_dec(&amplc,cp,1); loki_dec(&amplc,cp+8,4); for(i=0;i<10;i+=2) printf(“Block %01d = %08lx %08lx\n”, i/2,data[i],data[i+1]); } IDEA typedef typedef typedef typedef typedef unsigned char boolean; /* values are TRUE or FALSE */ unsigned char byte; /* values are 0–255 */ byte *byteptr; /* pointer to byte */ char *string;/* pointer to ASCII character string */ unsigned short word16; /* values are 0–65535 */ typedef unsigned long word32; /* values are 0–4294967295 */ #ifndef TRUE #define FALSE 0 #define TRUE (!FALSE) #endif /* if TRUE not already defined */ #ifndef min /* #define min(a,b) #define max(a,b) #endif /...
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