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

typedef unsigned int word32 else typedef unsigned

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: = leftt; return; } /* Validation sets: * * Single–length key, single–length plaintext – * Key : 0123 4567 89ab cdef * Plain : 0123 4567 89ab cde7 * Cipher : c957 4425 6a5e d31d * **********************************************************************/ void des_key(des_ctx *dc, unsigned char *key){ deskey(key,EN0); cpkey(dc–>ek); deskey(key,DE1); cpkey(dc–>dk); } /* Encrypt several blocks in ECB mode. Caller is responsible for short blocks. */ void des_enc(des_ctx *dc, unsigned char *data, int blocks){ unsigned long work[2]; int i; unsigned char *cp; cp = data; for(i=0;i<blocks;i++){ scrunch(cp,work); desfunc(work,dc–>ek); unscrun(work,cp); cp+=8; } } void des_dec(des_ctx *dc, unsigned char *data, int blocks){ unsigned long work[2]; int i; unsigned char *cp; cp = data; for(i=0;i<blocks;i++){ scrunch(cp,work); desfunc(work,dc–>dk); unscrun(work,cp); cp+=8; } } void main(void){ des_ctx dc; int i; unsigned long data[10]; char *cp,key[8] = {0×01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; char x[8] = {0×01,0x23,0x45,0x67,0x89,0xab,0xcd,0xe7}; cp = x; des_key(&ampdc,key); des_enc(&ampdc,cp,1); printf(“Enc(0..7,0..7) = ”); for(i=0;i<8;i++) printf(“%02x ”, ((unsigned int) cp[i])&amp0×00ff); printf(“\n”); des_dec(&ampdc,cp,1); printf(“Dec(above,0..7) = ”); for(i=0;i<8;i++) printf(“%02x ”,((unsigned int)cp[i])&amp0×00ff); printf(“\n”); cp = (char *) data; for(i=0;i<10;i++)data[i]=i; des_enc(&ampdc,cp,5); /* Enc 5 blocks. */ for(i=0;i<10;i+=2) printf(“Block %01d = %08lx %08lx.\n”, i/2,data[i],data[i+1]); des_dec(&ampdc,cp,1); des_dec(&ampdc,cp+8,4); for(i=0;i<10;i+=2) printf(“Block %01d = %08lx %08lx.\n”, i/2,data[i],data[i+1]); } LOKI91 #include <stdio.h> #define LOKIBLK #define ROUNDS typedef unsigned long extern Long extern char #ifdef extern extern extern #else extern #endif lokikey[2]; *loki_lib_ver; 8 16 Long; /* No of bytes in a LOKI data–block /* No of LOKI rounds */ */ /* type specification for aligned LOKI blocks */ /* 64–bit key used by LOKI routines */ /* String with version no. & copyright */ */ __STDC__ /* declare prototypes for library functions void enloki(char *b); void deloki(char *b); void setlokikey(char key[LOKIBLK]); /* else just declare library functions extern */ void enloki(), deloki(), setlokikey(); __STDC__ char P[32] = { 31, 23, 29, 21, 27, 19, 25, 17, }; 15, 7, 30, 22, 14, 6, 13, 5, 28, 20, 12, 4, 11, 3, 26, 18, 10,...
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