crypt(3) DES routines

Jon Boede jboede at auscso.UUCP
Fri Mar 18 14:23:51 AEST 1988


I posted a question on this a while back and it was summarily ignored, perhaps
because it's such an easy question... anyhow, I'm still trying to get it to
work.

What I'm looking for is a function that will encrypt or decrypt a string
passed to it using the DES functions in the standard library.  I have a v7
manual that documents this and it seems fairly simple yet I continue to have
no luck.

Assuming that I could attack a while string in 8 character (64 bit) chunks,
I've written the following which fails nicely because I immediately encrypt
then decrypt the bit array (block of chars) and I don't get back what I put
in!

Thanks,
Jon

main()
{
	char blk2[64], text[32], block[64], key[9];
	register bit, loop;

	strcpy(key,"xyzzy678");
	/* load and set the key block */
	for (loop=0; loop < 8; loop++) {
		for (bit=0; bit < 8; bit++)
			block[loop*8+bit] = ((int)key[loop] & (1<<bit)) ?
			'\1' : '\0';
	}
	setkey(block);

	strcpy(text,"thisisometext"); /* going to do just first 8 chars */
	for (loop=0; loop < 8; loop++)
		for (bit=0; bit < 8; bit++)
			block[loop*8+bit] = ((int)*(text+loop) & (1<<bit)) ?
			'\1' : '\0';
	for (loop=0; loop < 64; loop++)
		blk2[loop] = block[loop];
	encrypt(block,0); /* encrypt it */
	encrypt(block,1); /* decrypt it */
	for (loop=0; loop < 64; loop++)
		if (blk2[loop] != block[loop]) {
			puts("different");
			exit(0);
		}
	puts("same");
	exit(0);
}
-- 
Jon Boede		jboede at auscso.UUCP, jon%bodedo at im4u.cs.utexas.edu
1301 Trace Dr. #204, Austin, TX 78741-1735		(512) 462-3287
	"People who are incapable of making decisions are
	 the ones that hit those barrels at freeway exits."



More information about the Comp.lang.c mailing list