c# - Implementing XOR in a simple image encryption method -


so of guys finished creating simple image encrypter. it's enough keep non-tech person out, right? :p

now next step. suggested use xor. read xor , it's logical table determines answer between 2 bits, right?

only when 1 true, statement true.

0 0 = false 1 0 = true 0 1 = true 1 1 = false

is correct? so, how go xor encrypting image?

here's previous way using caeser cipher.

private void encryptfile()     {                     openfiledialog dialog = new openfiledialog();         dialog.filter = "jpeg files (*.jpeg)|*.jpeg|png files (*.png)|*.png|jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif";         dialog.initialdirectory = @"c:\";         dialog.title = "please select image file encrypt.";         byte[] imagebytes;         if (dialog.showdialog() == dialogresult.ok)         {             imagebytes = file.readallbytes(dialog.filename);              (int = 0; < imagebytes.length; i++)             {                 imagebytes[i] = (byte)(imagebytes[i] + 5);             }              file.writeallbytes(dialog.filename, imagebytes);         }                 }      private void decryptfile()     {         openfiledialog dialog = new openfiledialog();         dialog.filter = "jpeg files (*.jpeg)|*.jpeg|png files (*.png)|*.png|jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif";         dialog.initialdirectory = @"c:\";         dialog.title = "please select image file decrypt.";         byte[] imagebytes;         if (dialog.showdialog() == dialogresult.ok)         {             imagebytes = file.readallbytes(dialog.filename);              (int = 0; < imagebytes.length; i++)             {                 imagebytes[i] = (byte)(imagebytes[i] - 5);             }              file.writeallbytes(dialog.filename, imagebytes);         }                 } 

xor logical operation between 2 bits. benefit if run xor second time, undoes first time. change code to

imagebytes[i] = (byte)(imagebytes[i] ^ 5); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -