Re: Right way of using setkey(3) and encrypt(3)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: Right way of using setkey(3) and encrypt(3)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

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 supp
osed 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.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:05 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register