Encrypt method (from decrypt method)
Hi,
In the code below there is a method called "decrypt". I am trying to reverse the code to implement the corresponding "encrypt":
Code:
public partial class Form1 : Form
{
private uint P;
private uint Q;
private uint[] _S;
char[] k = new char[0x80];
public byte Crr
{
get
{
return 12;
}
}
public byte Crb
{
get
{
return 16;
}
}
public byte Crt
{
get
{
return 26;
}
}
public byte Crc
{
get
{
return 4;
}
}
//Constructor
public Form1()
{
this.P = 0xb7e15163;
this.Q = 0x9e3779b9;
this._S = new uint[this.Crt];
k[0] = '\x0017';
k[1] = '\x009b';
k[2] = '\x0084';
k[3] = '\x0096';
k[4] = 'V';
k[5] = '\x00f0';
k[6] = '\x0011';
k[7] = '\x00d1';
k[8] = '\x0088';
k[9] = '\x0082';
k[10] = '\x00bc';
k[11] = '\x00e4';
k[12] = '\x0089';
k[13] = 'C';
k[14] = '\x00da';
k[15] = '\x0091';
setup_S(k)
}
private void setup_S(char[] K)
{
int index = 0;
int num2 = 0;
int num3 = 0;
int num4 = licBase.Crw / 8;
uint[] numArray = new uint[this.Crc];
uint num5 = 0;
uint num6 = 0;
for (int i = 0; i < numArray.Length; i++)
{
numArray[i] = 0;
}
index = this.Crb - 1;
numArray[this.Crc - 1] = 0;
while (index != -1)
{
numArray[index / num4] = (numArray[index / num4] << 8) + K[index];
index--;
}
this._S[0] = this.P;
for (index = 1; index < this.Crt; index++)
{
this._S[index] = this._S[index - 1] + this.Q;
}
num5 = num6 = 0;
index = num2 = num3 = 0;
while (num3 < (3 * this.Crt))
{
num5 = this._S[index] = rotLeft(this._S[index] + (num5 + num6), 3);
num6 = numArray[num2] = rotLeft(numArray[num2] + (num5 + num6), num5 + num6);
num3++;
index = (index + 1) % this.Crt;
num2 = (num2 + 1) % this.Crc;
}
}
public uint rotRight(uint x, uint y)
{
uint num = x;
uint num2 = x;
for (uint i = 0; i < (y & (this.Crw - 1)); i++)
{
num = num >> 1;
}
for (uint j = 0; j < (this.Crw - (y & (this.Crw - 1))); j++)
{
num2 = num2 << 1;
}
return (num | num2);
}
public uint rotLeft(uint x, uint y)
{
uint num = x;
uint num2 = x;
for (uint i = 0; i < (y & (this.Crw - 1)); i++)
{
num = num << 1;
}
for (uint j = 0; j < (this.Crw - (y & (this.Crw - 1))); j++)
{
num2 = num2 >> 1;
}
return (num | num2);
}
public void decrypt(uint[] ct, uint[] pt)
{
uint y = ct[1];
uint num2 = ct[0];
for (uint i = this.Crr; i > 0; i--)
{
y = rotRight(y - this._S[(int)((IntPtr)((2 * i) + 1))], num2) ^ num2;
num2 = rotRight(num2 - this._S[(int)((IntPtr)(2 * i))], y) ^ y;
}
pt[1] = y - this._S[1];
pt[0] = num2 - this._S[0];
}
public void encrypt(uint[] ct, uint[] pt)
{
// HELP NEEDED
}
}
}
I am having a hard time trying to reverse the XOR in the decrypt method. If anyone can help I would highly appreciate it.
Thank you.