user1849946
user1849946

Reputation: 19

encrypting a Document using vigenere cipher

I'm interested in learning about different encryption techniques and have started to implement a vigenere cipher in c#. I can implement a windows forms which allows me to encrypt and decrypt a string similar the following link.

https://stackoverflow.com/questions/13533269/c-sharp-vigenere-cipher-to-encrypt-an-text-file

My question is how could I use vigenere to encrypt a word document or an image file instead of a string? I have created button which opens a dialog to let me choose a file, I'm now stuck on how to encrypt the chosen file. Anybody have any idea's?

Upvotes: 0

Views: 1801

Answers (1)

reza
reza

Reputation: 1369

Read the file into a byte array

byte[] bytes = File.ReadAllBytes("C:\folder\myfile");

then feed this into your encryption routine to produce a different byte[] array to write back to disk

bytesEncrypted = MyEncryptFunction(bytes);
File.WriteAllBytes("C:\folder\myfile.encrypted", bytesEncrypted)

Upvotes: 1

Related Questions