Re: [Vala] RC4 encryption algorithm



I stopped reading when I saw you are swapping the S box with integers instead of unsigned chars.

I have googled "rc4" for you from my phone and found two results in the first page that may give you some 
light..

http://forum.intern0t.net/c-c/783-rc4-algorithm.html
http://www.cypherspace.org/rsa/rc4c.html

On 27/10/2011, at 22:29, "Luis L. Rodríguez Oro" <luisr uci cu> wrote:

hello, I have some problem with RC4 encryption algorithm. I don't know in what point the algorithm be come 
asymmetric.

Please, help me.

string rc4_encrypt(string key, string text) {
   int S[255];
   int i;
   int len = key.length;
   int j = 0;
   int temp;

   for (i = 0; i < 255; i++)
       S[i] = i;

   for (i = 0; i < 255; i++) {
   int s = (int) key[i % len]; //ascii

   j = (j + S[i] + s) % 256;
       temp = S[i];
   S[i] = S[j];
   S[j] = temp;
   }

   i = j = 0;
   string conv="";
   for (var y = text; y.get_char () != 0; y = y.next_char ()) {
   int ansi = (int) y.get_char ();

   i = (i + 1) % 256;
   j = (j + S[i]) % 256;

   temp = S[i];
   S[i] = S[j];
   S[j] = temp;

   temp = ansi ^ S[(S[i] + S[j]) % 256];
   var cara = (char) temp;

   conv += cara.to_string();
   }
   return conv;
}


string rc4_decrypt(string key, string text) {
   return rc4_encrypt(key, text);
}

void main() {
   string encr = rc4_encrypt("Key", "Plaintext");
   string decr = rc4_decrypt("Key", encr);

   // the big problem is HERE!
   if (decr != "Plaintext")
      warning("do not work decrypt");
}


Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN 
PRISIONES DE LOS EEUU!
http://www.antiterroristas.cu
http://justiciaparaloscinco.wordpress.com
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]