static void Main(string[] args) { //---------- B B S ---------------- int[] seq = new int[length]; Console.WriteLine($"n = {n} (число Блюма)"); Console.WriteLine($"x = {x}\n"); int buf = x; long OldTicks = DateTime.Now.Ticks; for (int i = 0; i < length; i++) { buf = BBSnext(buf, i); seq[i] = buf; } Console.Write("\nПСП = "); foreach (int item in seq) { Console.Write($"{item}; "); } Console.WriteLine($"\nВремя зашифрования: {(DateTime.Now.Ticks - OldTicks) / 1000} мс"); //----------- R C 4 --------------- Console.WriteLine("\n\n\n ----------- R C 4 ---------------\n"); int[] ikey = { 1, 11, 21, 31, 41, 51 }; byte[] key = new byte[ikey.Length]; for (int i = 0; i < ikey.Length; i++) { key[i] = Convert.ToByte(ikey[i]); } RC4 rc = new RC4(key); RC4 rc2 = new RC4(key); byte[] testBytes = ASCIIEncoding.ASCII.GetBytes("Julia Chistyakova Alexandrovna"); byte[] encrypted = rc.Encode(testBytes, testBytes.Length); Console.WriteLine($"Зашифрованнная строка : {ASCIIEncoding.ASCII.GetString(encrypted)}"); byte[] decrypted = rc2.Encode(encrypted, encrypted.Length); Console.WriteLine($"Рашифрованнная строка : {ASCIIEncoding.ASCII.GetString(decrypted)}"); Console.ReadKey(); }
static void Main(string[] args) { byte[] key = ASCIIEncoding.ASCII.GetBytes("61"); RC4 encoder = new RC4(key); string test = "Romanovich Nikita"; byte[] testBytes = ASCIIEncoding.ASCII.GetBytes(test); byte[] result = encoder.Encode(testBytes, testBytes.Length); Console.WriteLine(Encoding.Default.GetString(result)); RC4 decoder = new RC4(key); byte[] decryptedBytes = decoder.Decode(result, result.Length); string decryptedString = ASCIIEncoding.ASCII.GetString(decryptedBytes); Console.WriteLine(decryptedString); Console.ReadKey(); }