}
// reverse for operation PHT (Pseudo Hadamard Transform)byte[] IPHT(byte x1, byte x2)
{intX1 = Convert.ToInt32(x1);intX2 = Convert.ToInt32(x2);diff1 = -intX1 + 2 * intX2;(diff1 < 0)+= 256;diff2 = intX1 - intX2;(diff2 < 0)+= 256;intY1 = diff1 % 256;intY2 = diff2 % 256;[] b = new byte[2];[1] = Convert.ToByte(intY1);[0] = Convert.ToByte(intY2);b;
}
// operation PHT (Pseudo Hadamard Transform)byte[] PHT(byte x1, byte x2)
{intX1 = Convert.ToInt32(x1);intX2 = Convert.ToInt32(x2);intY1 = (2 * intX1 + intX2) % 256;intY2 = (intX1 + intX2) % 256;[] b = new byte[2];[0] = Convert.ToByte(intY1);[1] = Convert.ToByte(intY2);b;
}byte[] execPHTStage(byte[] x, int round)
{[] b = new byte[8];[] temp = new byte[2];= this.PHT(x[0], x[1]);(round!= 0)
{[0] = temp[0];[4] = temp[1];
}
{.Copy(temp, 0, b, 0, 2);
}= this.PHT(x[2], x[3]);(round!= 0)
{[1] = temp[0];[5] = temp[1];
}
{.Copy(temp, 0, b, 2, 2);
}= this.PHT(x[4], x[5]);(round!= 0)
{[2] = temp[0];[6] = temp[1];
{.Copy(temp, 0, b, 4, 2);
}= this.PHT(x[6], x[7]);(round!= 0)
{[3] = temp[0];[7] = temp[1];
}
{.Copy(temp, 0, b, 6, 2);
}b;
}byte[] execIPHTStage(byte[] x, int round)
{[] b = new byte[8];[] temp = new byte[2];= this.IPHT(x[0], x[1]);(round!= 0)
{[0] = temp[0];[2] = temp[1];
}.Copy(temp, 0, b, 0, 2);= this.IPHT(x[2], x[3]);(round!= 0)
{[4] = temp[0];[6] = temp[1];
}.Copy(temp, 0, b, 2, 2);= this.IPHT(x[4], x[5]);(round!= 0)
{[1] = temp[0];[3] = temp[1];
}.Copy(temp, 0, b, 4, 2);= this.IPHT(x[6], x[7]);(round!= 0)
{[5] = temp[0];[7] = temp[1];
}.Copy(temp, 0, b, 6, 2);b;
}
// SAFER K-64 encryptionbyte[] encrypt()
{sourceLength = this.GetTextBlockLength(this.Text);[] key = Encoding.Default.GetBytes(this.Key);[] bigKey;[] bigKey2;[] sourceBlock = new byte[8];[] result = new byte[sourceLength * 8];(int round = 0; round < this.Round; round++)
{r = 0;(int i = 0; i < sourceLength; i++)
{= this.GetTextBlock8Byte(this.Text, i);
// Encryption Key advancing= this.GetKey(2 * (i + 1) - 1, key);= this.GetKey(2 * (i + 1), key);(int j = 0; j < sourceBlock.Length; j++)
{(j + 1)
{1:4:5:8:[r] = this.XOR(sourceBlock[j], bigKey[j]);[r] = this.E(result[r]);[r] = this.Mod256(result[r], bigKey2[j]);;:[r] = this.Mod256(sourceBlock[j], bigKey[j]);[r] = this.L(result[r]);[r] = this.XOR(result[r], bigKey2[j]);;
}++;
}[] temp = new byte[8];.Copy(result, r - 8, temp, 0, 8);= this.execPHTStage(temp, 1);= this.execPHTStage(temp, 2);= this.execPHTStage(temp, 0);.Copy(temp, 0, result, r - 8, 8);
}
}result;
}
// SAFER K-64 decryptionbyte[] decrypt()
{sourceLength = this.GetTextBlockLength(this.Text);[] key = Encoding.Default.GetBytes(this.Key);[] bigKey;[] bigKey2;[] sourceBlock = new byte[8];[] result = new byte[sourceLength * 8];(int round = 0; round < this.Round; round++)
{r = 0;(int i = 0; i < sourceLength; i++)
{= this.GetTextBlock8Byte(this.Text, i);[] temp = new byte[8];.Copy(sourceBlock, 0, temp, 0, 8);= this.execIPHTStage(sourceBlock, 1);= this.execIPHTStage(temp, 2);= this.execIPHTStage(temp, 0);.Copy(temp, 0, result, r, 8);= this.GetKey(2 * (i + 1) - 1, key);= this.GetKey(2 * (i + 1), key);(int j = 0; j < sourceBlock.Length; j++)
{(j + 1)
{1:4:5:8:[r] = this.DiffMod256(result[r], bigKey2[j]);[r] = this.L(result[r]);[r] = this.XOR(result[r], bigKey[j]);;:[r] = this.XOR(result[r], bigKey2[j]);[r] = this.E(result[r]);[r] = this.DiffMod256(result[r], bigKey[j]);;
}++;
}
}
}result;
}
}
}