Simple libdes example
Corrected to allow hex 0's to print
See the Helsinki University
of Technology site for a description and source of libdes.
Script started on Wed Aug 27 09:46:13 1997
sh-2.00$
sh-2.00$ cat prog1.c
#include <stdio.h>
#include "/usr/local/include/des.h"
/* Use libdes to encrypt one input under one key, then show result. */
void main(){
int i;
des_key_schedule schedule;
/* Key works even if parity isn't right. */
des_cblock key = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
des_cblock input = {0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef, 0xab, 0xcd};
des_cblock output;
i = des_set_key((C_Block *)key, schedule);
printf("%d\n",i);
des_ecb_encrypt((C_Block *)input, (C_Block *) output, schedule, 1);
for(i = 0; i < 8; i++)
{
printf("%2.2x", output[i]);
}
printf("\n");
}
sh-2.00$ cc prog1.c /usr/local/lib/libdes.a
sh-2.00$ a.out
0
cde872d4a471346f
sh-2.00$ exit
exit
script done on Wed Aug 27 09:47:07 1997