Click here to Skip to main content
14,360,787 members
   

C#

 
GeneralRe: How to clean all the installers? Pin
_Q12_7-Jun-19 20:40
member_Q12_7-Jun-19 20:40 
GeneralRe: How to clean all the installers? Pin
OriginalGriff7-Jun-19 21:11
protectorOriginalGriff7-Jun-19 21:11 
GeneralRe: How to clean all the installers? Pin
_Q12_8-Jun-19 9:24
member_Q12_8-Jun-19 9:24 
AnswerRe: How to clean all the installers? Pin
Gerry Schmitz7-Jun-19 7:31
mveGerry Schmitz7-Jun-19 7:31 
AnswerRe: How to clean all the installers? Pin
Eddy Vluggen7-Jun-19 9:38
mveEddy Vluggen7-Jun-19 9:38 
AnswerRe: How to clean all the installers? Pin
Dave Kreskowiak7-Jun-19 15:39
mveDave Kreskowiak7-Jun-19 15:39 
AnswerRe: How to clean all the installers? Pin
#realJSOP10-Jun-19 3:26
mve#realJSOP10-Jun-19 3:26 
QuestionIndex was Outside the range of the Array in Cryptography App Pin
Member 140791596-Jun-19 3:15
memberMember 140791596-Jun-19 3:15 
Hi!

Am trying to secure any chosen file with the supplied password in a Desktop Application in C#.
But index was out of range of the Array as almost make my work miserable.
I;ll be glad if anyone can assist me debug these codes.


This is my code
<pre>

else if (!(string.IsNullOrWhiteSpace(txtCryptoSecretKey.Text) && string.IsNullOrWhiteSpace(txtFilePath.Text)))
{
timerPrgBar.Enabled = true;
//try
//{
byte[] fileContent = File.ReadAllBytes(txtFilePath.Text);
byte[] passwordTmp = Encoding.ASCII.GetBytes(txtCryptoSecretKey.Text);
byte[] keys = new byte[fileContent.Length];
for (int i = 0; i < fileContent.Length; i++)
keys[i] = passwordTmp[i % passwordTmp.Length];

// Encrypt
byte[] result = new byte[fileContent.Length]; //Changed from byte to long
byte[] abc = new byte[fileContent.Length]; //Just Added

if (rbEncrypt.Checked)
{
table = new byte[0, 256]; //just added
for (int i = 0; i < fileContent.Length; i++)
{
byte value = fileContent[i];
byte key = keys[i];
int valueIndex = -1, keyIndex = -1;
for (int j = 0; j < 256; j++)
if (abc[j] == value)
{
valueIndex = j;
break;
}
//just added, from here
else
{
valueIndex = 0;
break;
}
// to here.
for (int j = 0; j < 256; j++)
if (abc[j] == key)
{
keyIndex = j;
break;
}
//just added, from here
else
{
keyIndex = 0;
break;
}
// to here.
//table = new byte[i,i]; //this worked but throwing out of bound array.
//Index was outside the bound of the Array
result[i] = table[keyIndex, valueIndex];

}

// Save result to new file with the same extension
String fileExt = Path.GetExtension(txtFilePath.Text);
SaveFileDialog sd = new SaveFileDialog();
sd.Title = "Save Encrypted File";
sd.Filter = "Files (*" + fileExt + ") | *" + fileExt;
if (sd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sd.FileName, result);
timerPrgBar.Enabled = true;
MessageBox.Show("Your File as been Encrypted Successfully.", "Secured!", MessageBoxButtons.OK, MessageBoxIcon.Information);

} //RemoveOwnedForm;

}
// Decrypt
else
{
table = new byte[0,256]; //just added
for (int i = 0; i < fileContent.Length; i++)
{
byte value = fileContent[i];
byte key = keys[i];
int valueIndex = -1, keyIndex = -1;
for (int j = 0; j < 256; j++)

if (abc[j] == key)
{
keyIndex = j;
break;
}
for (int j = 0; j < 256; j++)
if (table[keyIndex, j] == value)
{
valueIndex = j;
break;
}
result[i] = table[keyIndex, valueIndex];
//result[i] = abc[valueIndex];
}
// Save result to new file with the same extension
String fileExt = Path.GetExtension(txtFilePath.Text);
SaveFileDialog sd = new SaveFileDialog();
sd.Title = "Save Decrypted File";
sd.Filter = "Files (*" + fileExt + ") | *" + fileExt;
if (sd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sd.FileName, result);


timerPrgBar.Enabled = true;
MessageBox.Show("File Revealed Successfully.", "Revealed!", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}



}
}
</pre>
QuestionRe: Index was Outside the range of the Array in Cryptography App Pin
Richard MacCutchan6-Jun-19 3:45
protectorRichard MacCutchan6-Jun-19 3:45 
AnswerRe: Index was Outside the range of the Array in Cryptography App Pin
OriginalGriff6-Jun-19 3:57
protectorOriginalGriff6-Jun-19 3:57 
AnswerRe: Index was Outside the range of the Array in Cryptography App Pin
Gerry Schmitz6-Jun-19 7:33
mveGerry Schmitz6-Jun-19 7:33 
QuestionVS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 4:40
memberhoney the codewitch5-Jun-19 4:40 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
Richard MacCutchan5-Jun-19 5:35
protectorRichard MacCutchan5-Jun-19 5:35 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
Gerry Schmitz5-Jun-19 7:52
mveGerry Schmitz5-Jun-19 7:52 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 9:11
memberhoney the codewitch5-Jun-19 9:11 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
OriginalGriff5-Jun-19 9:20
protectorOriginalGriff5-Jun-19 9:20 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 9:30
memberhoney the codewitch5-Jun-19 9:30 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
ZurdoDev5-Jun-19 10:09
professionalZurdoDev5-Jun-19 10:09 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 14:59
memberhoney the codewitch5-Jun-19 14:59 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
ZurdoDev6-Jun-19 2:54
professionalZurdoDev6-Jun-19 2:54 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch6-Jun-19 4:16
memberhoney the codewitch6-Jun-19 4:16 
JokeRe: VS2017/2019 VSIX broken - I need a favor Pin
ZurdoDev6-Jun-19 4:23
professionalZurdoDev6-Jun-19 4:23 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch6-Jun-19 4:32
memberhoney the codewitch6-Jun-19 4:32 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
CPallini5-Jun-19 11:01
mveCPallini5-Jun-19 11:01 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
jschell8-Jun-19 6:01
memberjschell8-Jun-19 6:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.