Monday 28 October 2013

Basic Encryption/Decryption Of Your Data

If I am on a computer frequented by others and I have a personal file on there, I'll change it's name including the extension, or just leave it without an extension.
Eg. if I have a file 'Porn.Jpg', I'll rename it to 'Language.dll' or 'winhelp', so someone who sees that file usually will not wonder about it, because it looks like an official Windows file.
I used to use batch files to do this for multiple files.....good old DOS.

/*"But I do not see my file extensions :(". Open 'My Computer'>Alt+t>Folder Options>View>Uncheck 'Hide Extensions For Known File Types'>Ok. You will now be able to see your extensions. Check it back to undo this.*/

Sometimes they may be notepad files that I do not want others to read. It may contain my financial information, my recent online transactions, some less important passwords - we need so many passwords these days, and we don't want to use the same one for everything. If someone figures out one password, they have access to everything.

Besides renaming the extension, we can also use something like the following program to 'encrypt' the file. Admittedly it is a weak encryption, but that's okay because it's not like our problem is an intelligence agency trying to decrypt our stuff. If you do have that problem, I'm sure you know of better ways to hide your data.
But please, do not save your online banking password, Credit Card numbers etc. like this. The REALLY important stuff you NEED to memorize.

This encryption adds 100 to the ASCII value of each character and writes it to file, so it looks like gibberish when opened in notepad. But you can use the program to read it. You can change the 100 to any number.

For this program to work it will create a folder called 'MyFolder' in your C drive with a file called 'MyFile.dll' in it when you run it for the first time.
But if it is encrypted, why make it a '.dll' extension? Well, so that no one deletes it for one and also now it is double encrypted!!! Yeahhhhhh <nods head slowly>!
Run the program, choose to Enter Text, View File or Exit. If you press 'e', you can enter the text you want to record encrypted. Press 'v' and you can see all entries. Press 'x' and the program exits.

#include <stdio.h>
#include <stdlib.h>

void dc_dll(void);
void ec_dll(void);

FILE *fs,*ft;
char ch;

int main()
{
    char c,input[1000];

    fs=fopen("C:\\myfolder\\MyFile.dll","a");
    if(fs==NULL)
    {
        system("md c:\\MyFolder 2>nul");
        fs=fopen("c:\\myfolder\\MyFile.dll","w");
        if(fs==NULL)
        {
            printf("Cannot open C:\\MyFolder\\MyFile.dll. So bad :(");
            getch();
            exit(0);
        }
        fclose(fs);
        ec_dll();
    }
    else
    {
        fclose(fs);
    }
    printf("Enter Text, View File or Exit? (E/V/X)");
    while(1)
    {
        fflush(stdin);
        c=toupper(getch());
        if(c=='E')
        {
            printf("\nEnter text to save...\n");
            gets(input);
            dc_dll();
            fs=fopen("c:\\myfolder\\MyFile.dll","a");
            fprintf(fs,"%s\n\n",input);
            fclose(fs);
            ec_dll();
        }
        else if(c=='V')
        {
            printf("\n");
            dc_dll();
            fs=fopen("c:\\myfolder\\MyFile.dll","r");
            while(1)
            {
                ch=fgetc(fs);
                if(ch==EOF)
                {
                    break;
                }
                printf("%c",ch);
            }
            fclose(fs);
            ec_dll();
            printf("\nPress any key.....");
            getch();
        }
        else if(c=='X')
        {
            exit(0);
        }
        system("cls");
        printf("Enter Text, View File or Exit? (E/V/X)");
    }
    return 0;
}

void ec_dll(void)
{
    fs=fopen("c:\\MyFolder\\MyFile.dll","r");
    ft=fopen("c:\\MyFolder\\Data.temp","w");
    while(1)
    {
        ch=fgetc(fs);
        if(ch==EOF)
        {
            break;
        }
        fputc(ch+100,ft);

    }
    fclose(fs);
    fclose(ft);
    system("del c:\\MyFolder\\MyFile.dll");
    system("ren c:\\MyFolder\\Data.temp MyFile.dll");
}

void dc_dll(void)
{

    fs=fopen("c:\\MyFolder\\MyFile.dll","r");
    ft=fopen("c:\\MyFolder\\Data.temp","w");
    while(1)
    {
        ch=fgetc(fs);
        if(ch==EOF)
        {
            break;
        }
        fputc(ch-100,ft);

    }
    fclose(fs);
    fclose(ft);
    system("del c:\\MyFolder\\MyFile.dll");
    system("ren c:\\MyFolder\\Data.temp MyFile.dll");
}

No comments:

Post a Comment