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

typedef unsigned int word32 else typedef unsigned

Info icon This 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern