Mailing List Archive

What size should i use in encrypt/decrypt in ARC4 ?
Howdy ,..

I cannot understand what values i should use in encrypt /decrypt when using
gcry_cipher_encrypt :

for example when i run this code :

char * plain_text = "Attack at down";
char * c_str ;
c_str = new char[ strlen(plain_text) + 1 ];
strcpy ( c_str, plain_text);

gcry_check_version(NULL)
gcry_control( GCRYCTL_DISABLE_SECMEM_WARN );
gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
gcry_cipher_open (&cipher_handler,
GCRY_CIPHER_ARCFOUR,GCRY_CIPHER_MODE_STREAM, 0);
gcry_cipher_setkey (cipher_handler,"Secret", 128);

gcry_cipher_encrypt (cipher_handler,c_str,strlen(c_str) , NULL,0);
cout<<c_str<<endl;

gcry_cipher_decrypt (cipher_handler, c_str,strlen(c_str),NULL,0);
cout<<c_str<<" " <<endl;

i get the next output :

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


while i should get :

45A01F645FC35B383552544B9BF5
Attack at down

What values should i use in sizes (since i guess i made there some error .
Re: What size should i use in encrypt/decrypt in ARC4 ? [ In reply to ]
On Wed, Jul 30, 2008 at 5:42 AM, Jabka Atu <mashrom.head@gmail.com> wrote:
> char * plain_text = "Attack at down";

Firstly, it should be 'dawn', otherwise you army will return -EINVAL
and the barbarian hoards will overrun them ;)

> gcry_cipher_encrypt (cipher_handler,c_str,strlen(c_str) , NULL,0);
> cout<<c_str<<endl;
>
> gcry_cipher_decrypt (cipher_handler, c_str,strlen(c_str),NULL,0);
> cout<<c_str<<" " <<endl;
>
> i get the next output :
>
> ��g�zB�QK]o
> ��A�R���� 2�9�

I'm just guessing here, but it's a stream cipher and you're reusing
the same cipher_handler. If you tried creating two handles for the
cipher (and setting the same key on both, of course) and used one for
encryption and the other for decryption, you might have better luck.
The reason is that RC4 mutates itself as it processes the plaintext[1]

AGL

[1] http://en.wikipedia.org/wiki/RC4

--
Adam Langley agl@imperialviolet.org http://www.imperialviolet.org
_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel