mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-24 15:26:48 -05:00
Auto calc pad offset on BoxUp test page
This commit is contained in:
parent
15bbba55db
commit
86cdf830a7
|
|
@ -21,19 +21,24 @@ namespace PkmnFoundations.GTS.debug
|
|||
|
||||
}
|
||||
|
||||
private static byte[] PAD = new byte[256];
|
||||
|
||||
protected void btnSend_Click(object sender, EventArgs e)
|
||||
{
|
||||
phDecoded.Visible = false;
|
||||
byte[] data = fuBox.FileBytes;
|
||||
FileStream s = File.Open(Server.MapPath("~/Box Upload Xor Pad.bin"), FileMode.Open);
|
||||
byte[] pad = new byte[s.Length];
|
||||
s.Read(pad, 0, pad.Length);
|
||||
s.Read(PAD, 0, PAD.Length);
|
||||
s.Close();
|
||||
int padOffset = Convert.ToInt32(txtOffset.Text);
|
||||
|
||||
for (int x = 6; x < data.Length; x++)
|
||||
if (txtOffset.Text.Length > 0)
|
||||
{
|
||||
data[x] ^= pad[(x + padOffset) % 256];
|
||||
int padOffset = Convert.ToInt32(txtOffset.Text);
|
||||
Encrypt(data, padOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
Decrypt(data);
|
||||
}
|
||||
|
||||
litDecoded.Text = RenderHex(data.ToHexStringLower());
|
||||
|
|
@ -56,5 +61,20 @@ namespace PkmnFoundations.GTS.debug
|
|||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static void Encrypt(byte[] data, int padOffset)
|
||||
{
|
||||
// encrypt and decrypt are the same operation...
|
||||
for (int x = 6; x < data.Length; x++)
|
||||
{
|
||||
data[x] ^= PAD[(x + padOffset) % 256];
|
||||
}
|
||||
}
|
||||
|
||||
public static void Decrypt(byte[] data)
|
||||
{
|
||||
int padOffset = (Array.IndexOf(PAD, data[6]) + 250) % 256;
|
||||
Encrypt(data, padOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user