Thread: How to decrypt / encrypt using libgcrypt ? (ARC4)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    111

    How to decrypt / encrypt using libgcrypt ? (ARC4)

    Howdy ,..

    I'm reaading libgcrypt manual but
    I cannot understand what values i should use in encrypt /decrypt when using gcry_cipher_encrypt :

    for example when i run this code :
    Code:
    #include <stdio.h>
    #include <gcrypt.h>
    #include <assert.h>
    
    int main()
    {
    
      gcry_cipher_hd_t handle;
      gcry_error_t err = 0;
      char * plain_text ;
      char * out ;
      char * deout ;
    
      size_t size_of_plain = sizeof(char) * 6;
      size_t size_of_crypt = sizeof(char) * 601;
      plain_text = malloc (size_of_plain);
      out =  malloc (size_of_crypt);
      deout = malloc (size_of_crypt);
      assert(plain_text);
      assert(out);
      assert(deout);
    
      strcpy(plain_text , "Secret");
      
    
      gcry_check_version (NULL);
      gcry_control( GCRYCTL_DISABLE_SECMEM_WARN );
      gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
    
    
           {
    
    
           err = gcry_cipher_open (&handle, GCRY_CIPHER_ARCFOUR,GCRY_CIPHER_MODE_STREAM,0);
     
           if (err)
             {
               fprintf (stderr, "Failure: &#37;s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
               fprintf (stdout, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
    
             }
    	err = gcry_cipher_setkey (handle, "This is really strange , i read the documentation i googled for two days and nothing , i can't encrypt && decrypt",128);
    	if (err)
             {
               fprintf (stderr, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
               fprintf (stdout, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
    
             }
         }
      err =  gcry_cipher_encrypt (handle,
              (unsigned char *)out, sizeof(out), (const unsigned char *)plain_text,sizeof plain_text);
    if (err)
             {
               fprintf (stderr, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
               fprintf (stdout, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
    
             }
      printf(" out :%s ||| plain text %s\n",out, plain_text);
    err =  gcry_cipher_encrypt (handle,
              (unsigned char *)deout, sizeof deout, (const unsigned char *)out,sizeof out);
    if (err)
             {
               fprintf (stderr, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
               fprintf (stdout, "Failure: %s/%s\n",
                        gcry_strsource (err),
                        gcry_strerror (err));
    
             }
      printf("deout: %s ||| out: %s ||| plain text: %s\n",deout, out,plain_text);
      
      free(plain_text);
      free(out);
      free(deout);
      gcry_cipher_close(handle);
      return 0;
    
    }
    i get the next output :

    Code:
    ��g�zB�QK]o
    ��A�R����       2�9�

    while i should get according to wikipedia :

    Code:
    45A01F645FC35B383552544B9BF5
    Attack at down
    What should i do to fix it ?
    Last edited by jabka; 07-30-2008 at 01:30 PM.
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange issue utilizing encrypt() in libcrypt
    By TheComedian in forum C Programming
    Replies: 8
    Last Post: 01-18-2009, 07:14 AM
  2. Encrypt text using a Digital Certififcate
    By magic.mike in forum Windows Programming
    Replies: 0
    Last Post: 01-11-2009, 03:53 AM
  3. dll to encrypt packet sends
    By splintter in forum C++ Programming
    Replies: 22
    Last Post: 04-20-2008, 09:00 PM
  4. encrypt input message
    By axedia in forum C Programming
    Replies: 1
    Last Post: 05-30-2005, 12:48 AM
  5. Ask about Encrypt data 2 times.
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 07-16-2002, 03:28 AM