Re: encrypt and decrypt using encrypt(char block[64], int edflag)
From: rockwell (rockwell_001_at_yahoo.com)
Date: 07/26/04
- Next message: Larry I Smith: "Re: uid (user authentication)"
- Previous message: Janina Kramer: "uid (user authentication)"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: encrypt and decrypt using encrypt(char block[64], int edflag)"
- Next in thread: David Schwartz: "Re: encrypt and decrypt using encrypt(char block[64], int edflag)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Jul 2004 16:33:30 -0700
Hi jens,
I am really thankful to u man,this has solved my problem,it
works now.I appreciate that.Once again thanks man.
Bye.
Jens.Toerring@physik.fu-berlin.de wrote in message news:<2mhpqqFm835sU1@uni-berlin.de>...
> rockwell <rockwell_001@yahoo.com> wrote:
> > Hi groups i am trying to encrypt and decrypt back a block of data .I
> > am using the standard encrypt(char block[64], int edflag) function. I
> > have written a small program which should do this according to the man
> > page.the program looks like
>
> > #include <stdio.h>
> > #include <unistd.h>
> > #include <crypt.h>
>
> > int main(void)
> > {
> > char key[64];
> > char txt[64]="myblockofdata";
>
> > strcat(key, "thisismystring");
>
> > printf("Before encrypting");
> > printf("txt is %s",txt);
> > printf("\n");
> > setkey(key);
>
> > printf("After encrypting");
> > encrypt(txt, 0);
> > printf("txt is %s",txt);
> > printf("\n");
>
>
> > printf("After decrypting");
> > encrypt(txt, 1);
> > printf("txt is %s",txt);
> > printf("\n");
> > return 0;
> > }
>
>
> > but this program does not display any thing except the string before
> > encrypting.Can u suggest me what to do and how to proceed. According
> > to the manpage on encrypt it just says if edflag is 0 it encrypts and
> > if edflag is 1 it decrypts and i even want to know what does this mean
> > void setkey(const char *key). The key parameter used here is an array
> > of bytes, having each byte the numerical value 1 or 0. Does this mean
> > that the key parameter should contain only 0's and 1's.
>
> Yes. And also the text you want to encrypt or decrypt need to be
> converted to something that consists of 1 and 0's only! So out of
> each char you're going to encrypt you first have to make an array
> of 8 chars. Here's a program that shows one wy how you can do that:
>
> #define _XOPEN_SOURC
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <crypt.h>
>
> int main(void)
> {
> char key[64];
> char orig[ 9 ]= "myblocko";
> char buf[64];
> char txt[ 9 ];
> int i, j;
>
> for ( i = 0; i < 64; i++ )
> key[ i ] = rand( ) & 1;
>
> printf("Before encrypting: %s\n", orig);
> for ( i = 0; i < 8; i++ )
> for ( j = 0; j < 8; j++ )
> buf[ i * 8 + j ] = orig[ i ] >> j & 1;
> setkey(key);
>
> encrypt(buf, 0);
> for ( i = 0; i < 8; i++ )
> for ( j = 0, txt[ i ] = '\0'; j < 8; j++ )
> txt[ i ] |= buf[ i * 8 + j ] << j;
> txt[ 9 ] = '\0';
> printf("After encrypting: %s\n", txt);
>
> encrypt(buf, 1);
> for ( i = 0; i < 8; i++ )
> for ( j = 0, txt[ i ] = '\0'; j < 8; j++ )
> txt[ i ] |= buf[ i * 8 + j ] << j;
> txt[ 9 ] = '\0';
> printf("After decrypting: %s\n", txt);
> return 0;
> }
>
> If you take a closer look at this
>
> for ( i = 0; i < 8; i++ )
> for ( j = 0; j < 8; j++ )
> buf[ i * 8 + j ] = orig[ i ] >> j & 1;
>
> It takes the characters from 'orig' and spreads them over 8 bytes for
> each of the charatcters, putting this into the buffer to be converted.
> After the encryption/decryption you need to do the reverse to get back
> at text. (Since encrypt() only takes a buffer of 64 bytes I had to
> cut back your original string to 8 characters, more wont fit into
> the 64 byte wide buffer.) In contrast to your program I am using a
> random key - if you want instead to use your string you also have to
> spread the first 8 chars over the 64 byte key.
>
> Regards, Jens
- Next message: Larry I Smith: "Re: uid (user authentication)"
- Previous message: Janina Kramer: "uid (user authentication)"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: encrypt and decrypt using encrypt(char block[64], int edflag)"
- Next in thread: David Schwartz: "Re: encrypt and decrypt using encrypt(char block[64], int edflag)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|