Beispiel #1
0
        }//adding text to encrypted/decrypted files by block

        private static string rc4plus(string slovo, string key) //return encoded/decoded text
        {
            string    chiper;
            VarsValue vars = new VarsValue();

            vars   = KSA(vars, key);
            chiper = PRGA(vars, slovo);
            return(chiper);
        }
Beispiel #2
0
        private static string PRGA(VarsValue vars, string slovo) //(PRGA) Pseudo Random Generation Algorithm
        {
            for (vars.s = 0, vars.n = 0, vars.o = 0, vars.r = 0; vars.o < slovo.Length; vars.o++)
            {
                vars.s         = (vars.s + 1) % 256;
                vars.r         = vars.i[vars.s];
                vars.n         = (vars.n + vars.r) % 256;
                vars.r         = vars.i[vars.s];
                vars.i[vars.s] = vars.i[vars.n];
                vars.i[vars.n] = vars.r;
                vars.r         = vars.i[((vars.s << 5) ^ (vars.n >> 3)) % 256] + vars.i[((vars.n << 5) ^ (vars.s >> 3)) % 256];
                vars.a        += Convert.ToChar((slovo.ToCharArray(vars.o, 1)[0])
                                                ^ ((vars.i[(vars.i[vars.s] + vars.i[vars.n]) % 256] + vars.i[(vars.r ^ 0xAA) % 256]) ^ vars.i[(vars.n + vars.i[vars.s]) % 256]) % 256);
            }

            return(vars.a);
        }
Beispiel #3
0
        private static VarsValue KSA(VarsValue vars, string key) //(KSA) Key Scheduling Algorithm
        {
            for (vars.n = 0, vars.a = "", vars.s = 0; vars.s < 256; vars.s++)
            {
                vars.i[vars.s] = vars.s;
            }

            for (vars.s = 0; vars.s < 256; vars.s++)
            {
                vars.n         = (vars.n + vars.i[vars.s] + Convert.ToInt32(key.ToCharArray(vars.s % key.Length, 1)[0])) % 256;
                vars.r         = vars.i[vars.s];
                vars.i[vars.s] = vars.i[vars.n];
                vars.i[vars.n] = vars.r;
            }

            return(vars);
        }