因此,我正在为一个学校项目工作,该项目允许我加密大文件,但是对于某些(可能是32位相关的)问题,它无法打开大于3 GB的文件。 你能发现我的错误吗?
我已经用long代替了整数
private void Form1_Load(object sender, EventArgs e)
{
rbEncrypt.Checked = true;
// init abc and table
abc = new byte[256];
for (long i = 0; i < 256; i++)
abc[i] = Convert.ToByte(i);
table = new byte[256, 256];
for(long i = 0; i < 256; i++)
for(long j = 0; j< 256; j++)
{
table[i, j] = abc[(i + j) % 256];
}
}
private void BtStart_Click(object sender, EventArgs e)
{
// Checking input values
if(!File.Exists(tbPath.Text))
{
MessageBox.Show("File does not exist");
return;
}
if(string.IsNullOrEmpty(tbPassword.Text))
{
MessageBox.Show("Pass is empty");
return;
}
// get file content and key for encrypting
try
{
byte[] filecontent = File.ReadAllBytes(tbPath.Text);
byte[] passwordTmp = Encoding.ASCII.GetBytes(tbPassword.Text);
byte[] keys = new byte[filecontent.Length];
for (long i = 0; i < filecontent.Length; i++)
keys[i] = passwordTmp[i % passwordTmp.Length];
//Encrypt
byte[] result = new byte[filecontent.Length];
if (rbEncrypt.Checked)
{
for (long i = 0; i < filecontent.Length; i++)
{
long value = filecontent[i];
long key = keys[i];
long valueIndex = -1, keyIndex = -1;
for (long j = 0; j < 256; j++)
if (abc[j] == value)
{
valueIndex = j;
break;
}
for (long j = 0; j < 256; j++)
if (abc[j] == key)
{
keyIndex = j;
break;
}
result[i] = table[keyIndex, valueIndex];
}
}
//Decrypt
else
{
for (long i = 0; i < filecontent.Length; i++)
{
long value = filecontent[i];
long key = keys[i];
long valueIndex = -1, keyIndex = -1;
for (long j = 0; j < 256; j++)
if (abc[j] == key)
{
keyIndex = j;
break;
}
for (long j = 0; j < 256; j++)
if (table[keyIndex, j] == value)
{
valueIndex = j;
break;
}
result[i] = abc[valueIndex];
}
}
感谢您的帮助。我很想弄清楚这一点,但我找不到任何东西,并且一直在为HOURS而苦苦挣扎。