Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all, i am using a function to get the TEXT from a texbox, XOR it, then save to a file:

C#
private static string encryptDecrypt(string input) {
        char[] key = {'K', 'C', 'Q'}; //Any chars will work, in an array of any size
        char[] output = new char[input.Length];

        for(int i = 0; i < input.Length; i++) {
            output[i] = (char) (input[i] ^ key[i % key.Length]);
        }

        return new string(output);
    }


Writing to file, XOR all working, BUT i have a richtextbox, in wich i want to open the file and see the current content, of course line by line ( because the file is a list ).
The problem is, i get a really wierd Exception: "Error in opening file, illegal characters found" bla bla...

C#
try
               {
                   if ((myStream = openFileDialog1.OpenFile()) != null)
                   {
                       using (myStream)
                       {
                           richTextBox1.Text = System.IO.File.ReadAllText(encryptDecrypt(openFileDialog1.FileName));
                       }
                   }
               }


Can somebody explain me what am i doing wrong? It should decrypt the file, and output it to my richtextbox1.

Note: without xor all works ok, and without xor... wel it`s useless.
Posted

1 solution

Um.
You do realise that what you are doing is decrypting the filename, then trying to open that as a file?
So you will pass "D:\Temp\MyFile.encrypt" to your decryption method, and get back "&!^%£&"£!^£)("!£NB"£F" which you then pass to the file as a valid path...:laugh:
Try:
C#
richTextBox1.Text = encryptDecrypt(System.IO.File.ReadAllText(openFileDialog1.FileName));
 
Share this answer
 
Comments
[no name] 24-May-15 4:49am    
Oh my god! you do realise that you have saved my day no? :D Thank you so much ...
OriginalGriff 24-May-15 4:55am    
You're welcome!
[no name] 24-May-15 4:51am    
@OriginalGriff - Thank you again, i am so sorry i cannot tell details, nor put any info here about my software... but i can show this: [DELETED] this is my work :D thanks again!

[edit]link removed - OriginalGriff[/edit]
OriginalGriff 24-May-15 4:58am    
I've removed your web link - it's not a good idea to post such things here, it looks like site driving spam and that will get your account banned very quickly indeed! :laugh:
[no name] 24-May-15 4:59am    
Yeah Ok, i understand, :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900