Topic : XOR Encryption Tutorial
Author : Kias Henry
Page : 1 Next >>
Go to page :


Computer Encryption, an overview and programming.
TOPICS:


1.0   - Encryption what is it?
1.1   - Is encryption even worthy?
1.2   - Yeah yeah, how do I encrypt stuff?
1.3   - Programming - Fundamentals
1.4   - Binary
1.5   - XOR, AND, ONES COMPLIMENTRY -Logical operators
1.6   - Structured C Programming.
1.7   - Encryption Example


Why are you reading this?
    Learn the basics to xor encryption and write your own program.
    Some programming knowledge is required, languages C/C++ will be fine.


1.0 Encryption, What is it?

Encryption, what the hell?
Yeah that's right, encryption. A Great Way to secure your privacy.
Especially for all you l33t crack3rs out there.
I know you want to jump to the programming so I'll just give you the
Dictionary idea on what encryption is:
Encrypt:
1. To put a message into code;
2. To put computer data into an encoded form
'
Ok, you just got a new computer and your now a leet user right?
You download all the tools but theres one that catches your eye..
It asks you to enter the Filename of the file you want to encrypt so
you do as it says, and pick your mums business file, work.dat
it loads for a while and then says, encryption complete, you feel
as though you could take on an army you feel leet.

Two days later, your mum is unable to complete her job for work and loses
her job, you innocently deny the events that ruined up her datafile.
But deep down you feel guilty, you hate encryption and never want to see
it again.

Wrong! 'MOST' encryption programs are released with a 'decryptor'
You ARE able to turn mums work back into readable format!
Unfortunately for this guy, he has no decryption and is banned from his
computer for the rest of his teenage hood.

Ok, encryption turns your mums great work files into useless code that's
Unreadable, ready to continue on?

1.1 Is encryption even worthy?
Privacy is a growing issue on the internet these days. Encryption is a good defence against people finding out your private information.


1.2 Yeah yeah how do I encrypt stuff?

Its easy, download and run an encryption program. Parse all the correct
parameters to the encryptor and WALA!
If your using a good encryptor is should be able to DE-CRYPT in one.
If you would like a FULLY WORKING ENCRYPTION PROGRAM refer to the example
program at the bottom of this page!

1.3 Programming Fundamentals!

Lets Pretend were writing an encryption program in 'English'
it would look like this:

ask for file1 to encrypt
ask for file2 to output encrypted data too
encrypt file1 and save as file2 leave file1 untouched

Although this tutorial is C based, I will now show you a
visual basic example followed by a C example for all of you
without C experience.  Ohh and for all of you with no experience,
bye. Nah you can stay, maybe you'll learn something :)

Visual Basic:
   private sub commandbutton1_click()
   dim file1,file2 as integer;     ` I know this is wrong, but
   file1 = inputbox("File to Encrypt"); `were pretending...
   file2 = inputbox("File to output to"); `remember????
   encrypt
   end sub
END VISUAL Basic

C:
  FILE *stream1,stream2;
  
  if((stream1 = fopen(argv[1], "rb")) == NULL) { /*ERROR*/ }
  if((stream2 = fopen(argv[2], "wb")) == NULL) { /* ERROR*/}
   encrypt(file1,file2);
  END C!


Ok, if I have lost you. Read the next section otherwise skip it -=)

NExt Section:
stream1 and 2 are simply  pointers to of type FILE
argv[1] is the commandline parameter passed to programs in dos.
example:

program file1 file2 key
file1 is argv[1]
program is argv[0]
file2 is argv[2] and key is argv[3]
Ok so we know how to accept parameters! or do we? Here's an example
help you understand:

#include

  int main(int argc, char *argv[])
  {
     printf("Parameter 1 is %s, 2 is %s.\n", argv[1], argv[2]);
     printf("Program name is %s.\n", argv[0];
     printf("Number of parameters: %d\n", argc);
   return 0;
  }

Ok if it doesn't make sense, compile it with you favorite C compiler.
Note: If you don't have a compiler, you obviously don't know how to program ?
And this file may be a little extensive, programming wise for your liking.
If you want keep reading feel free =)

Note: The best way to learn is to teach people, so go and teach all
your friends how to use argv and argc you'll be the coolest kid in school!
I promise.

1.4 Binary
Binary, hmmm and it would be?
Answer: The only language the computer really understands.
Although you may type some programs up and compile them, wether it be
pascal,C,asm,delphi,vb,fortran or your dads billygoat your computer does
not read what you tell it to, I know it sux, but its the truth.
All your pretty little code is converted into a jumple of 1's and 0's.
But you may protest, pfft what a load of shit, my programs contain advanced
algorithms that couldnt possibly be defined with 1's and zero's. Wrong,
every event which takes place on your computer is just a sequence of commands
Heres an example that will enlighten you a little, the typical hello world
program:

int main()
{
while(1)
printf("Hello, World!\n");

return 0;
}

This program is my enhancement to the original, this baby can produce 10000
Instances of hello world in under 1 minute!
Actually, it simply loops for ever displaying the inevitable. Lets look at
what really happens.
Warning, ASM to follow:

.data
msg db "Hello, World!",13,10,"$" ; 13,10 is equivalent to \n
.code
   START:
    mov ax, seg msg
    mov ds, ax
    mov dx, offset msg
    mov ah, 09
    int 21h
    jmp START
END START


This program does exactly as the C program does, but you are able to see how it does what it does. Take attention to the jmp START instruction!
Remember how a while loop loops until a condition is false? What you don't?
Maybe that's because I haven't taught you yet. Here's the Catch. All it does is jmp to the start again, and executes all the instructions again!
All this time you thought it involved magic etc. Pfft

But you start to speak, "This 'aint' binary dude", yes indeed its not.
But as you are about to find out, Your cute little C hello world program
is converted to ASM so windows can run it!
Computers are seriously stupid and only do what they are told.
Ok, your asm code is then converted to 1's and 0's so the processor can read
it.  Do I see a pattern?

  Notepad.exe
   hello.c
    //code
     compiler/linker etc
      operating system
       processor
  

Now that we have that settled, lets learn some Binary!

BINARY NUMBER SYSTEM:
Decimal - Binary
   1         0001
   2         0010
   3         0011
   4         0100
   5         0101
   6         0110
   7         0111
   8         1000
   16       10000
   32      100000
   64     1000000
   128   10000000
   256  100000000

Character - Decimal - Binary
        a        97        01100001
        z       123        01111011

I'm sure you can figure the rest out.. :)

Repeat to yourself, I now know binary!

1.4 Logical operator, AND, XOR, ONES COMPLIMENTARY

Ok, in this section you need to know binary, so please read the above section

LOGICAL 'AND'
And  1 0
1 1 0
0 0 0

Therefore 1 'And' 1 = 1 Also 1 'And' 0 = 0 It can easily be seen from this truth table that 'And' will take two bits, and produce a result from these two bits. The 'And' operator in C is '&' . & will only return 1 when both bits are 1.


LOGICAL 'XOR'
XOR  1 0
1  0 1
0  1 0


ONES COMPLIMENT which is this operator in the c language: '~'
Example-
By applying ones compliment to the decimal number 21845 each bit in this number will be inversed.
Decimal:  2184      01010101 01010101
~Decimal: 42945450  10101010 10101010


As above, we apply the ~ operator to decimal 21845.
It simply turns 1's to 0's and 0's to ones. The number 21845 is changed to 42945450 because of this

Page : 1 Next >>