Rexor Documentation

Rexor is an encryption algorithm developed with cryptography beginners in mind. It's designed to be simple and easy to use and a good starting point for beginners. The algorithm is written in VB.NET but I hope to expand on that soon. Rexor stands for RE REverse XOR Exclusive OR. I am actively working on the project and I hope to get some more people soon.

Here is a step-by-step analysis of the code.
How it works:

Starting from the very top, this four line snippet imports the necessary namespaces needed to execute the code. Without these we wouldn't be able to use most of the commands below.

Imports Microsoft.VisualBasic
Imports System.Text
Imports System.Security.Cryptography
Imports System.IO

This line says what the block of text is called, Rexor.

Module Rexor

This block of code is the main function. It is called when a programmer wants to encrypt a string.

Public Function Rexorcrypt(ByVal Input As String, ByVal Key As String) As String
Return xorstring(Reverse(xorstring(Input, Key)), Key)
End Function

This line declares the encrypt function's name and the variables it needs to execute.

Private Function xorstring(ByVal input As String, ByVal key As String) As String

In this block we declare the variables needed in order to store the necessary information required to carry out the algorithm successfully.

Dim Result1 As String
key = Hashkey(key)
Dim a As Array = input.ToCharArray
Dim k As Array = key.ToCharArray
Dim q As Integer = 0

Where it says ‘Key = Hashkey(Key)’ we turn the Password (Key) into a SHA1 Hash so if the key is bob, then the hash is "SBgazSKz7a68ikR4aKfffOYpkgo="

But that was just calling the function, here is the code:

Private Function Hashkey(ByVal key As String)
'Hash the key
Dim sha1CryptoService As New SHA1CryptoServiceProvider()
Dim byteValue = Encoding.UTF8.GetBytes(key)
Dim hashValue = sha1CryptoService.ComputeHash(byteValue)
Return Convert.ToBase64String(hashValue)
End Function

After that these lines turn the hashed key and the input string into character arrays.

Dim a As Array = input.ToCharArray
Dim k As Array = key.ToCharArray

Here the function finds the character codes of each letter in the ket and input strings and then xor’s them together.

For i = 0 To a.Length - 1
If q = 27 Then
q = 0
End If
'Dim k As String = Mid((key), q, 1)
Result1 = Result1 + Chr((Asc(k(q))) Xor Asc(a(i)))
q = q + 1
Next

The result is returned and the function ended.

Return Result1
End Function

But up to here, we have only xor’d the input string with the key once, now the algorithm moves onto reversing the output string and then xoring the old output with the key again.

Public Function Rexorcrypt(ByVal Input As String, ByVal Key As String) As String
Return xorstring(Reverse(xorstring(Input, Key)), Key)
End Function

(The reverse function is:

Private Function Reverse(ByVal input As String)
'Reverse the string
'Turn the string into an array
Dim rev() As Char = input.ToCharArray
'Reverse the array
Array.Reverse(rev)
'Convert the array to a string again.
Return CStr(rev)
End Function

)

So we:
- Xored a string with a hashed key
- Reversed the result
- Xored the result with the hashed key again
- Returned the result.

Email me: tyopdfdf@live.co.uk

Last edited Jan 27, 2010 at 6:08 PM by Todd434, version 6

Comments

No comments yet.