While hand-rolled encryption is never a good idea, sometimes you don't need a high-security solution. SillyStream is a text I/O class that you can set a few parameters on and then do low-volme encrypted text file I/O. It would need optimization if you really need to work on large files, but it was really intended for smaller items such as settings files.
Usage
Pretty simple, just add SillyStream.cls to your Project. Then create instances as you need them (each only handles one file at a a time). Call Init() to set the parameters, then one of the open methods (input, output, append), and use the read and write methods, and finally the close method. Then you can open a new file either with or without setting new parameters first.
Parameters
There are two mask values (one a Byte, another a Long) and two dimensional parameters. These have funny names in the class and in the demo Project. See the comments for an explanation.
Cipher Used Here
This is a combination cipher, based on two very very simple ciphers.
The main feature here is a transposition cipher using the two dimensions provided to create a buffer block as a matrix. When writing or reading the file, the data is an inversion of this matrix.
On top of that we have a simple (really simple) substitution cipher. Each of the data characters is XORed with a one-Byte mask. With some effort you could use a longer "password" mask but it complicates things (especially "open append" operations).
The final block is padded with pseudorandom values.
Finally, to make this work even with a padded final block, the actual data length is stored in the first 4 bytes of the file as a Long value. This is XORed with the Long mask you provide for the purpose to help obscure it a bit. Adding these 4 bytes has another advantage: It makes it all little tougher to crack because simply trying to factor the file size will be a bit of a red herring even if someone guesses it uses a rectangular transposition cipher.
Dumb but cheap, and perhaps good enough.
Demo
The demo Project lets you open a new file, type some stuff, write it as characters or as a line (adding newline), etc, and then close. Then you can read it back and see it displayed, using either reading by byte count or the slower reading by line.
Even though slower, I expect most people to just read by line most of the time. Writing by line is probably going to be more useful than by text length as well.
Sample inputs:
Code:
This is a test.
This is only a test.
How now, brown cow?
Mellow yellow, such a silly fellow!
Test test test test test test test test test test testing!
Hex dump of a test with the data XORing omitted. Normally you wouldn't do this but it shows that the transposition and padding can be effective all alone: