Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[C#][VB .NET][SRC]XOR Class

The original source was from Aeonhack. I updated it with string parameter overloads, and also translated it into C# for my fellow coders.

So here it is:

C#
Code
class XOREncryption
{
    /// <summary>
    /// Encrypts your data via XOR. Original source by Aeonhack. Updated and translated by Ethereal of HackForums.net
    /// Leave the credits.
    /// </summary>
    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

    public string XORData(string data, string password) {  
  return encoding.GetString(XORData(encoding.GetBytes(data), encoding.GetBytes(password)));
    }

    public byte[] XORData(byte[] data, byte[] password)
    {
  int x = password.Length;
  for (int index = 0; index < data.Length; index++)
  {
    data[index] = Convert.ToByte(data[index] ^ password[index % x]);
  }
  return data;
    }

}

Usage:
Code
txtBox.Text = XOREncryption.XORData("Test text", "TestKeyVal");
txtBox.Text = XOREncryption.XORData(YourByteArrData, YourByteArrPass);

VB .NET
Code
Class XOREncryption
    'Original Byte() function by Aeonhack. Updated by Ethereal of HackForums.net
    'Leave the credits.
    Dim encoding As New System.Text.UTF8Encoding()

    Function XORData(ByVal data As String, ByVal password As String) As String
  Return encoding.GetString(XORData(encoding.GetBytes(data), encoding.GetBytes(password)))
    End Function

    Function XORData(ByVal data As Byte(), ByVal password As Byte()) As Byte()
  Dim X As Integer = password.Length
  For I As Integer = 0 To data.Length - 1
    data(I) = data(I) Xor password(I Mod X)
  Next
  Return data
    End Function
End Class

Usage:
Code
TextBox1.Text = XOREncryption.XORData("Test Data", "Test Pass")
Dim ByteArr As Byte() = XOREncryption.XORData(YourByteArrData, YourByteArrPass)
μεγαλομανία
Thank's for the share bro :).

Nice share, thanks for this.
Good thing your ported it for us C# coders! thanks!
Nice share, Ethereal.~
Another thing that can help me learn about encryption.~
Why not just make the string overload call the byte overload?
Also your for loop will miss the last item in the data byte[].
(Jan 23, 2011 04:29 PM)Zer0Fact0r Wrote:  Why not just make the string overload call the byte overload?
Also your for loop will miss the last item in the data byte[].

Thanks for notifying me of that - I will update it tonight.

I created two seperate functions for readability.

μεγαλομανία
PHP Code

<?php 
for (int index = 0; index < sData.Length - 1; index++) 

You will miss the last item.

It should be:
PHP Code

<?php 
for (int index = 0; index < sData.Length; index++) 
(Jan 24, 2011 12:17 AM)Nonmod Wrote:  
PHP Code

<?php 
for (int index = 0; index < sData.Length - 1; index++) 

You will miss the last item.

It should be:
PHP Code

<?php 
for (int index = 0; index < sData.Length; index++) 

I did notice that, but I was just working from the original source be Aeonhack.

I will be sure to update it.

EDIT: Updated! The VB class was fine, but the C# class needed it changed. Made slightly more efficient for you, Zer0.
μεγαλομανία


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by MiguelSanchezJun 5, 2022 10:47 PM 5 303 Jun 5, 2022 10:47 PM
Last Post: MiguelSanchez
[C] by lockheadApr 22, 2021 07:10 AM 0 145 Apr 22, 2021 07:10 AM
Last Post: lockhead
[Python] by DumbChickenApr 7, 2021 03:24 AM 4 186 Apr 7, 2021 03:24 AM
Last Post: DumbChicken