Ошибка с присвоением значения - C#
Формулировка задачи:
Здравствуйте! Можете подсказать как решить проблему с присвоением значения в классе Program.
class Realize
{
private byte G0(byte a, byte b)
{
return (byte)((((a + b) % 256) << 2) | (((a + b) % 256) >> 6));
}
private byte G1(byte a, byte b)
{
return (byte)((((a + b + 1) % 256) << 2) | (((a + b + 1) % 256) >> 6));
}
public byte[] F(byte[] x)
{
byte[] y = new byte[4];
y[1] = G1((byte)(x[0] ^ x[1]), (byte)(x[2] ^ x[3]));
y[0] = G0(x[0], y[1]);
y[2] = G0(y[1], (byte)(x[2] ^ x[3]));
y[3] = G1(y[2], x[3]);
return y;
}
private void AddKeyPart(byte[] P, byte[] K)
{
for (int i = 0; i < 4; i++)
{
P[i] = (byte)(P[i] ^ K[i]);
}
}
private byte[] XOR(byte[] a, byte[] b)
{
byte[] c = new byte[a.Length];
for (int i = 0; i < c.Length; i++)
{
c[i] = (byte)(a[i] ^ b[i]);
}
return c;
}
public byte[] Encrypt(byte[] P, byte[][] K)
{
byte[] LeftPart = new byte[4];
byte[] RightPart = new byte[4];
Array.Copy(P, 0, LeftPart, 0, 4);
Array.Copy(P, 4, RightPart, 0, 4);
AddKeyPart(LeftPart, K[6]);
AddKeyPart(RightPart, K[7]);
byte[] Round2Left = XOR(LeftPart, RightPart);
byte[] Round2Right = XOR(LeftPart, F(XOR(Round2Left, K[0])));
byte[] Round3Left = Round2Right;
byte[] Round3Right = XOR(Round2Left, F(XOR(Round2Right, K[1])));
byte[] Round4Left = Round3Right;
byte[] Round4Right = XOR(Round3Left, F(XOR(Round3Right, K[2])));
byte[] Round5Left = Round4Right;
byte[] Round5Right = XOR(Round4Left, F(XOR(Round4Right, K[3])));
byte[] Round6Left = Round5Right;
byte[] Round6Right = XOR(Round5Left, F(XOR(Round5Right, K[4])));
byte[] CipherTextLeft = XOR(Round6Left, F(XOR(Round6Right, K[5])));
byte[] CipherTextRight = XOR(Round6Right, CipherTextLeft);
byte[] CipherText = new byte[8];
Array.Copy(CipherTextLeft, 0, CipherText, 0, 4);
Array.Copy(CipherTextRight, 0, CipherText, 4, 4);
return CipherText;
}
public byte[] Decrypt(byte[] P, byte[][] K)
{
byte[] LeftPart = new byte[4];
byte[] RightPart = new byte[4];
Array.Copy(P, 0, LeftPart, 0, 4);
Array.Copy(P, 4, RightPart, 0, 4);
byte[] Round6Right = XOR(LeftPart, RightPart);
byte[] Round6Left = XOR(LeftPart, F(XOR(Round6Right, K[5])));
byte[] Round5Right = Round6Left;
byte[] Round5Left = XOR(Round6Right, F(XOR(Round6Right, K[4])));
byte[] Round4Right = Round5Left;
byte[] Round4Left = XOR(Round5Right, F(XOR(Round5Right, K[3])));
byte[] Round3Right = Round4Left;
byte[] Round3Left = XOR(Round4Right, F(XOR(Round4Right, K[2])));
byte[] Round2Right = Round3Left;
byte[] Round2Left = XOR(Round3Right, F(XOR(Round2Right, K[1])));
byte[] Round1Right = Round2Left;
byte[] Round1Left = XOR(Round2Right, F(XOR(Round1Right, K[0])));
byte[] TextLeft = Round1Left;
byte[] TextRight = XOR(Round1Left, Round1Right);
AddKeyPart(TextLeft, K[6]);
AddKeyPart(TextRight, K[7]);
byte[] Text = new byte[8];
Array.Copy(TextLeft, 0, Text, 0, 4);
Array.Copy(TextRight, 0, Text, 4, 4);
return Text;
}
} class Program
{
static void Main(string[] args)
{
byte[] x = new byte[8];
for(int i = 0; i < 8; i++)
x[i] = byte.Parse(Console.ReadLine());
Console.WriteLine();
byte[][] y = new byte[8][];// как присвоить значение???
Realize real = new Realize();
Console.WriteLine(real.Encrypt(x, y));
Console.ReadKey();
}
}Решение задачи: «Ошибка с присвоением значения»
textual
Листинг программы
byte[] x = new byte[8] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[][] y = new byte[8][];
for (int i = 0; i < 8; i++)
y[i] = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
Realize real = new Realize();
string s = real.Encrypt(x, y).ToString();
Console.WriteLine(s);