Click here to Skip to main content
15,892,161 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to clean all the installers? Pin
_Q12_7-Jun-19 19:40
_Q12_7-Jun-19 19:40 
GeneralRe: How to clean all the installers? Pin
OriginalGriff7-Jun-19 20:11
mveOriginalGriff7-Jun-19 20:11 
GeneralRe: How to clean all the installers? Pin
_Q12_8-Jun-19 8:24
_Q12_8-Jun-19 8:24 
AnswerRe: How to clean all the installers? Pin
Gerry Schmitz7-Jun-19 6:31
mveGerry Schmitz7-Jun-19 6:31 
AnswerRe: How to clean all the installers? Pin
Eddy Vluggen7-Jun-19 8:38
professionalEddy Vluggen7-Jun-19 8:38 
AnswerRe: How to clean all the installers? Pin
Dave Kreskowiak7-Jun-19 14:39
mveDave Kreskowiak7-Jun-19 14:39 
AnswerRe: How to clean all the installers? Pin
#realJSOP10-Jun-19 2:26
mve#realJSOP10-Jun-19 2:26 
QuestionIndex was Outside the range of the Array in Cryptography App Pin
Member 140791596-Jun-19 2:15
Member 140791596-Jun-19 2: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 2:45
mveRichard MacCutchan6-Jun-19 2:45 
AnswerRe: Index was Outside the range of the Array in Cryptography App Pin
OriginalGriff6-Jun-19 2:57
mveOriginalGriff6-Jun-19 2:57 
AnswerRe: Index was Outside the range of the Array in Cryptography App Pin
Gerry Schmitz6-Jun-19 6:33
mveGerry Schmitz6-Jun-19 6:33 
QuestionVS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 3:40
mvahoney the codewitch5-Jun-19 3:40 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
Richard MacCutchan5-Jun-19 4:35
mveRichard MacCutchan5-Jun-19 4:35 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
Gerry Schmitz5-Jun-19 6:52
mveGerry Schmitz5-Jun-19 6:52 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 8:11
mvahoney the codewitch5-Jun-19 8:11 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
OriginalGriff5-Jun-19 8:20
mveOriginalGriff5-Jun-19 8:20 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 8:30
mvahoney the codewitch5-Jun-19 8:30 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
ZurdoDev5-Jun-19 9:09
professionalZurdoDev5-Jun-19 9:09 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch5-Jun-19 13:59
mvahoney the codewitch5-Jun-19 13:59 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
ZurdoDev6-Jun-19 1:54
professionalZurdoDev6-Jun-19 1:54 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch6-Jun-19 3:16
mvahoney the codewitch6-Jun-19 3:16 
JokeRe: VS2017/2019 VSIX broken - I need a favor Pin
ZurdoDev6-Jun-19 3:23
professionalZurdoDev6-Jun-19 3:23 
GeneralRe: VS2017/2019 VSIX broken - I need a favor Pin
honey the codewitch6-Jun-19 3:32
mvahoney the codewitch6-Jun-19 3:32 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
CPallini5-Jun-19 10:01
mveCPallini5-Jun-19 10:01 
AnswerRe: VS2017/2019 VSIX broken - I need a favor Pin
jschell8-Jun-19 5:01
jschell8-Jun-19 5: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.