Simple File Encryption

    For my encryption needs I use PGP 8 but I am still using Win XP SP3 and PGP8 will not run in newer versions of Windows so sooner or later I will have to give it up. 
    I have often thought of the need of an encryption system which is secure, simple and does not rely on a particular software or operating system.  For example, if you want to write something which is meant to be disclosed many years in the future (like a will) you would not want to use software which will probably no longer be supported then.  So I set out to create a system which depends only on a simple process which can be done with simple tools available today and in the future with the same or other tools. 
    It is based on the concept of one time pad.    

In cryptography, the one-time pad (OTP) is an encryption technique that cannot be cracked if used correctly. In this technique, a plaintext is paired with a random secret key (also referred to as a one-time pad). Then, each bit or character of the plaintext is encrypted by combining it with the corresponding bit or character from the pad using modular addition. If the key is truly random, is at least as long as the plaintext, is never reused in whole or in part, and is kept completely secret, then the resulting ciphertext will be impossible to decrypt or break.

    So, provided we meet those conditions it is unbreakable but note that the key is of the same length or size as the document to be encrypted and this makes it not very practical for encrypting very large amounts of data but it is very well suited for a few files which do not need to be decrypted often.  Even though the strict rule is that the same key should not be used more than once, in practical terms we can use the same key for several files, specially if we are just trying to keep the files from ordinary people and not from the Government. The Government don't care what encryption you use because they just beat you up until you tell them what they want to know.
    The simple encryption system I propose works using the exclusive OR (XOR) operation and only needs a simple program which can XOR two files byte by byte.  I am using XorFiles which is tiny (16 KB) and does not require any installation.  You just copy it to a folder and it does its thing.  There are many other programs which can do the same thing and we can be quite sure that many decades from now there will be programs which can do this.
    Example 1: Download the encrypted file IMG_8388.jpg.crypt and the key IMG_8388.jpg.key, and use XorFiles to "XOR" them.  Name the result IMG_8388.jpg and you should be able to see the photo. 
    Notice several things which are due to the properties of the XOR operation.
    1.- The order of the files does not matter.  File01.crypt (XOR) Key01.file produces the same result as Key01.file (XOR) File01.crypt.
    2.- The three files (plain file, encrypted file and key file) are related in such way that XORing any two of them will produce the third one.  This is one reason to not reuse a key.  If somebody has access to an encrypted file and the corresponding plain file then they can get the key by just XORing the two files.  If the same key was used to encrypt other files then they can be decrypted.
    Ideally the plain file and the key file have the same number of bytes but as long as the original key file is longer it does not matter because XORFiles will truncate the output file to the length of the shortest file of the two.  So if you want to encode a file of 56,866 bytes you should use as key a file at least that long and the resulting encrypted file will be 56,866 bytes long.  Then you can XOR the original plain file with the encrypted file and obtain the key file of exactly the same length but you can also use the original, longer key file.
    You can use this technique to encrypt any type of file but if you want it to be useful a long time in the future you are safer sticking with file formats which will not become obsolete.  A plain text file is pretty much guaranteed to be readable into the distant future but a proprietary format may require special software to open it and that software may no longer be around then.
    Creating key files: Note that any file can be used as a key provided it is longer than the file to be encrypted.  If you have folders with tons of jpg photos, mp3 files, etc. you can very easily XOR several of these files to create your own new key file.  Note that compressed file formats like MP3, JPG, video formats, ZIP, etc. provide good byte randomness and successively XORing several in a row should provide a reasonably random stream of bytes.  You can even use a few EXE files and Windows files as inputs.  If you want to encrypt a file to sent to a friend you can encrypt it using a file or files you both have and no one else has.  The header of standard files have set formats so it is best to combine several different file formats. 
    The previous paragraph describes a simple way of creating keys which should be secure enough for common use.  You can encrypt the important file and leave it to one person and leave the key to another person and they need to collaborate to decrypt the file.  If it is your will or something similar which you want to be opened whenever you die then you can leave the file in your safe deposit box and give the key to another person with instructions.  You can even make the key by XORing several "pre-key" files and distribute these among different people so they need to cooperate in order to decrypt the file or files. 
    Creating better key files: There are several ways of creating or obtaining random bytes to be used as keys.  Random.org is one source and an Internet search will reveal others. 
    Also, random bytes can be quite easily created by recording random noise and then compressing the file using MP3 or other compression. Also video files are quite random so you can record random video which will be compressed. ZIP files are also quite compressed and random.  Ideally we should get rid of the file header and tail as they are not so random. 
    I will now introduce HexEdit which, like XORFiles, is also a very simple program which does not require installation.  It allows editing of files at the byte level and can be used to manipulate our encryption key files.  You can load a file and then cut off some parts, merge other files, etc.  Load the file and you will see the bytes in HEX notation.  Click Address - Goto and type any address and it will take you there.  Then click edit- delete to cursor to delete the first part or delete from cursor to delete the last part.  Also File - Insert to insert another file at that point.  This is enough to allow you to create truly random files.  Combine several files by XORing them and you can be sure you have a truly random key.  The more you XOR it the more random it gets. 
   

Updated
6 AUG 2016 - Created page