using System; public class Programm { const int ROUNDS_COUNT = 12; static byte[] conversionTable = new byte[256]; public static void Encrypt(ref uint l, ref uint r, uint key) { for (int round = 0; round < ROUNDS_COUNT; round++) { r ^= F(l, key); uint tempR = r; r = l; l = tempR; } } public static void Decrypt(ref uint l, ref uint r, uint key) { for (int round = 0; round < ROUNDS_COUNT; round++) { l ^= F(r, key); uint tempR = r; r = l; l = tempR; } } private static uint F(uint x, uint key) { x = SBlock(x); x += key; x >>= 3; x = SBlock(x); return x; } private static uint SBlock(uint x) { byte[] bytes = BitConverter.GetBytes(x);//разделяем входное число на 4 элемента for (int i = 0; i < bytes.Length; i++) { bytes[i] = conversionTable[bytes[i]]; //совершаем подстановку из таблицы } x = BitConverter.ToUInt32(bytes, 0); //соединяем преобразованное число return x; } public static void Main() { for (int i = 0; i < 256; i++) { conversionTable[i] = (byte)((i * (i + 1) >> 1) % 256); } uint key = 1211431230; //uint l = 0; //uint r = 0; Console.WriteLine("Введите первую ветвь(l):"); uint l = Convert.ToUInt32(Console.ReadLine()); Console.WriteLine("Введите вторую ветвь(r):"); uint r = Convert.ToUInt32(Console.ReadLine()); Console.WriteLine("Ветви: l = " + l + " r = " + r); Encrypt(ref l, ref r, key); Console.WriteLine("l = " + l + " r = " + r); Decrypt(ref l, ref r, key); Console.WriteLine("l = " + l + " r = " + r); Console.ReadKey(); } }