Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

Xor Encryption

Sometimes when making an application that outputs or inputs data, it sometimes proves useful to encrypt or shuffle the data around so that when opened with a text editor, the data cannot be easily read. Though this is very useful, the method of encryption and encryption algorithim is not complex and can be easily broken with a brute force cracker.

Well, let's get started. First off, you should make a new Module. In this new module, place the follwing code into the General Declarations area:

Global code As String
Global datastring As String

The two strings, CODE and DATASTRING stand for two different things. Code is the key code you will use to encrypt and decrypt the string. The code string can be any combonation of letters, numbers and characters. The total length of the code string can be around 300 characters (the longer the better), just remember that the code string cannot contain spaces. Now, datastring is the string you wish to encrypt or decrypt. This string can be of any size, ranging from small 10 character strings to entire letters or documents for e-mail purposes.

Before we continue, create a text box on your form and a commands button, then place the following into the command button coding.

Sub command1_click()
code = "abcdef"
datastring = "I once had a dog who ate a fly"
translate
End Sub

The above code will take the string in datastring and encrypt it using the key found in code. After you finish this, go back to your module and creat a new procedure called translate. The translat procedure will take the information and either decode or encode the datastring and send the information to the Textbox on your form.

Sub translate()
Dim temp As String
Dim i As Integer
Dim location As Integer
'DataString$ is the string you want to encode/decode.
temp$ = ""
'this temporarily holds the encrypted string
For i% = 1 To Len(datastring$)
location% = (i% Mod Len(code$)) + 1
'this little operation gives you the next byte location in the
'CODE string, looping back to the beginning when it reaches the
'end
temp$ = temp$ + Chr$(Asc(Mid$(datastring$, i%, 1)) Xor Asc(Mid$(code$, location%, 1)))
'perform the XOR operation
Next i%
form1.textbox1.text = temp$
End Sub

At the end we see the code form1.textbox1.text = temp$ which takes the chenged datastring and shows the output in a text box.

Well, that's it for this tutorial. If you want to see more information or have a correction or addition, please e-mail me.

If you would like to make a tutorial, please e-mail me.


Comments and suggestions are welcome.
Copyright c 1996 Heller Productions