[Vala] RC4 encryption algorithm



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



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