Click here to Skip to main content
Click here to Skip to main content

A simple 32-bit block file encryption application

By , 25 Jun 2007
 

Screenshot - x0r1.png

Introduction

I think this can go without saying, but I'll say it anyway: I realize there are encryption algorithms that are far superior to the one I am presenting here. That is not the purpose of this application. The purpose of this application is to demonstrate to potential encryption enthusiasts the possibilities of developing a very simple encryption application without resorting to extreme mathematical complexities.

How does it work?

The code is broken down into two major sections: a section for encryption and another for decryption. Each section is composed of a while loop that retrieves 4 bytes per cycle from a user-specified file to form a 32-bit unsigned integer block of data. This 32-bit unsigned integer block of data is then xored with a pseudo-random unsigned integer value that is seeded by one or more keys and then is rotated to the left or to the right in pseudo-random directions and magnitudes. This process is continued until the end of the file is reached. If a file is found to have a file size that is not divisible by 4, this application will use methods that perform calculations on 24-bit, 16-bit, or 8-bit unsigned integer blocks of data.

The following programmatically demonstrates the process of encrypting a block of 4 bytes:

// Main loop for encrypting a file


    while((a = fgetc(in)) != EOF && (b = fgetc(in)) != 
        EOF && (c = fgetc(in)) != EOF && (d = fgetc(in)) != EOF)
    {
        polarity = rand()%2;
        magnitude = rand()%32;
        block = ((d<<24) | (c<<16) | (b<<8) | a);
        block ^= ((rand()%256<<24) | (rand()%256<<16) | 
                (rand()%256<<8) | rand()%256);
        if (polarity) block = ROTL32(block,magnitude);
        else block = ROTR32(block,magnitude);
        putc(block,out);
        putc(block=block>>8,out);
        putc(block=block>>8,out);
        putc(block=block>>8,out);
    }

The following visually demonstrates the behavior of the above code:

Using the program

This program was originally designed to run on a Windows Operating System. To encrypt or decrypt a set of files, first select the intended files and drag them to the executable. The program will start and accept the files you just dragged and dropped as "command-line parameters". If this was done correctly, the files you selected will appear in a list. You can then specify a set of integer values that are within the range of 0 and 4292870144 as keys for seeding the pseudo-random number generator. Once you have indicated a set of keys, you will be asked if you want to encrypt or decrypt the selected files. Choose accordingly.

Note: To decrypt a file, you must specify the set of keys in reverse order.

History

  • 16 June, 2007 -- Original version posted
  • 25 June, 2007 -- Downloads updated

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

defconomicron
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralUsage of rand.memberJohn M. Drescher27 Jun '07 - 7:24 
GeneralRe: Usage of rand.memberYogesh Dhakad7 Jun '08 - 10:48 
GeneralRe: Usage of rand. - Found the CAUSE of the problem. No solution thoughmemberYogesh Dhakad8 Jun '08 - 5:30 
GeneralRe: Usage of rand. - Found the CAUSE of the problem. No solution thoughmemberYann11 Sep '08 - 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 25 Jun 2007
Article Copyright 2007 by defconomicron
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid