Unix Programming - Re: Right way of using setkey(3) and encrypt(3)

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > December 2004 > Re: Right way of using setkey(3) and encrypt(3)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Right way of using setkey(3) and encrypt(3)
Wayne C. Morris

2004-12-16, 7:45 pm

In article <1103201296.447112.45930@f14g2000cwb.googlegroups.com>,
cnystrom@gmail.com wrote:

> YBH123 wrote:
>
> I do not know.
>

[snip]
> /* bit pattern for key */
> char key[64] =
> " 1234567890123456789012345678901234567890
12345678901234567890123";
>
> /* bit pattern for messages */
> char txt[64] =
> " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN
OPQRSTUVWXYZ0123456789_";
>
> setkey(key);
>
> printf("|%s|\n", txt);
>
> encrypt(txt, 0); /* encode */

[snip]
> This does not work. The text after decode is not the same as the text
> before encode. Obviously, I am not understanding something.
>
> Can someone point out to me what I am doing wrong?


You're trying to use 64-byte strings. Both key[] and txt[] are supposed to
be 64-byte arrays of 1's and 0's (numeric values, not ASCII digits).

Here's a corrected version of your test program:
[vbcol=seagreen]
#include <stdio.h>
#include <crypt.h>


void display( char *msg )
{
int i;
for (i=0; i<64; i++)
{
printf( "%1d", (msg[i] ? 1 : 0) );
}
printf("\n");
}


int main()
{
/* bit pattern for key */
char key[64] =
{
1,0,0,1,0,1,0,0, 1,0,1,0,1,0,1,1, 1,1,0,0,0,1,0,1, 1,1,1,1,0,0,0,1,
0,0,0,1,0,0,1,0, 1,1,1,0,0,0,1,0, 1,0,1,1,0,1,0,0, 1,0,1,0,1,0,1,1
};

/* bit pattern for messages */
char txt[64] =
{
0,0,1,1,0,1,0,0, 0,1,0,0,1,0,1,1, 0,1,0,1,0,1,1,0, 0,0,1,0,1,0,0,0,
1,0,1,0,1,1,0,0, 1,0,1,0,0,0,1,0, 1,0,1,0,1,0,0,0, 1,0,1,1,1,0,1,1
};


setkey(key);

display(txt);

encrypt(txt, 0); /* encode */

display(txt);

encrypt(txt, 1); /* decode */

display(txt);
}
<<<

For a more practical program, you'd want to add functions to convert an
8-byte string into a 64-byte array of 1's and 0's, and vice versa.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com