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

.NET 

[VB.NET] XTEA Encryption [Source]

XTEA Encryption


I am back :)

XTEA is TEA's precursor. This is based on TEA Encryption will little improvements. More info can be found here!

Source :

Code
Public Class XTea
    'Leave a thanks....

    '- decompiler

    Private Shared f_key As UInteger()

    Public Sub New(ByVal password As String)
  f_key = FormatKey(password)
    End Sub

    Public Function Encrypt(ByVal input As String) As String
  If input.Length = 0 Then
    Throw New ArgumentException("Invalid input length!")
  End If

  If input.Length Mod 2 <> 0 Then
    input += ControlChars.NullChar
  End If

  Dim dataBytes As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)

  Dim cipher As String = String.Empty
  Dim tempData As UInteger() = New UInteger(1) {}
  For i As Integer = 0 To dataBytes.Length - 1 Step 2
    tempData(0) = dataBytes(i)
    tempData(1) = dataBytes(i + 1)
    code(tempData, f_key)
    cipher += ConvertUIntToString(tempData(0)) + ConvertUIntToString(tempData(1))
  Next

  Return cipher
    End Function

    Public Function Decrypt(ByVal Data As String) As String
  Dim x As Integer = 0
  Dim tempData As UInteger() = New UInteger(1) {}
  Dim dataBytes As Byte() = New Byte((Data.Length \ 8) * 2 - 1) {}
  For i As Integer = 0 To Data.Length - 1 Step 8
    tempData(0) = ConvertStringToUInt(Data.Substring(i, 4))
    tempData(1) = ConvertStringToUInt(Data.Substring(i + 4, 4))
    decode(tempData, f_key)
    dataBytes(x) = CByte(tempData(0))
    x += 1
    dataBytes(x) = CByte(tempData(1))
    x += 1
  Next
  Dim decipheredString As String = System.Text.ASCIIEncoding.ASCII.GetString(dataBytes, 0, dataBytes.Length)
  If decipheredString(decipheredString.Length - 1) = ControlChars.NullChar Then
    decipheredString = decipheredString.Substring(0, decipheredString.Length - 1)
  End If
  Return decipheredString
    End Function

    Private Shared Function FormatKey(ByVal Key As String) As UInteger()
  If Key.Length <= 5 Then
    Throw New ArgumentException("Key must be between 6 and 16 characters in length")
  End If

  Key = Key.PadRight(16, " "c).Substring(0, 16)

  Dim formattedKey As UInteger() = New UInteger(4) {}

  Dim j As Integer = 0
  For i As Integer = 0 To Key.Length - 1 Step 4
    formattedKey(j) = ConvertStringToUInt(Key.Substring(i, 4))
    j += 1
  Next
  Return formattedKey
    End Function

    Private Shared Sub code(ByVal v As UInteger(), ByVal k As UInteger())
  Dim y As UInteger = v(0)
  Dim z As UInteger = v(1)
  Dim sum As UInteger = 0
  Dim delta As UInteger = &H9E3779B9UI

  For i = 0 To 31
    y += (z << 4 Xor z >> 5) + z Xor sum + k(sum And 3)
    sum += delta
    z += (y << 4 Xor y >> 5) + y Xor sum + k(sum >> 11 And 3)
  Next

  v(0) = y
  v(1) = z
    End Sub

    Private Shared Sub decode(ByVal v As UInteger(), ByVal k As UInteger())
  Dim y As UInteger = v(0)
  Dim z As UInteger = v(1)
  Dim sum As UInteger = &HC6EF3720UI
  Dim delta As UInteger = &H9E3779B9UI

  For i = 0 To 31
    z -= (y << 4 Xor y >> 5) + y Xor sum + k(sum >> 11 And 3)
    sum -= delta
    y -= (z << 4 Xor z >> 5) + z Xor sum + k(sum And 3)
  Next

  v(0) = y
  v(1) = z
    End Sub

    Private Shared Function ConvertStringToUInt(ByVal Input As String) As System.UInt32
  Dim output As UInt32
  output = Convert.ToUInt32(Input(0))
  output += (Convert.ToUInt32(Input(1)) << 8)
  output += (Convert.ToUInt32(Input(2)) << 16)
  output += (Convert.ToUInt32(Input(3)) << 24)
  Return output
    End Function
    Private Shared Function ConvertUIntToString(ByVal Input As System.UInt32) As String
  Dim output As New System.Text.StringBuilder()
  output.Append(Convert.ToChar(Input And &HFF))
  output.Append(Convert.ToChar((Input >> 8) And &HFF))
  output.Append(Convert.ToChar((Input >> 16) And &HFF))
  output.Append(Convert.ToChar((Input >> 24) And &HFF))
  Return output.ToString()
    End Function

End Class

Output :

[img]http://ploader.net/files/743101b5744d2c56f961988109d931e8.gif[/img]


Note : You need to input a password between 6 (or 7 char min.) to 16 (max.) for this to work.

Enjoy!🤝



Big mess there! Sorry guys...
Hm, could you try to decrease the amount of code? Just wondering if that was possible as people would like to use this in their crypter, and they would like small stubs xD.
Nice... but it's create a lot of chars...
How hard would this be to crack? Bruteforce etc..
very nice decompiler thanks for this!
oh wow this is epic! thanks!
Thanks everyone, RC6 is what I am working. Hope I can get it working :)

(Nov 13, 2010 07:40 AM)DarkShadowz Wrote:  Hm, could you try to decrease the amount of code? Just wondering if that was possible as people would like to use this in their crypter, and they would like small stubs xD.

I gave the source. Now its up to you how you optimize the code :)

(Nov 13, 2010 09:43 AM)This Girl Is On Fire Wrote:  How hard would this be to crack? Bruteforce etc..

You can salt the encryption. That will make it even stronger.
But choose a random password or something and you are good to go.
(Nov 13, 2010 07:40 AM)DarkShadowz Wrote:  Hm, could you try to decrease the amount of code? Just wondering if that was possible as people would like to use this in their crypter, and they would like small stubs xD.

Just create a DLL, would drastically decrease the amount of code, and would make it easier to feature this in crypters and such.
Can I port this to C#? I will give credits.
(Nov 13, 2010 11:32 AM)Mr. Anderson Wrote:  Can I port this to C#? I will give credits.

Yes you can.
Convert it in C# or use a DLL.
nicee, is this polymorphic?
(Nov 18, 2010 08:57 PM)memesbro Wrote:  nicee, is this polymorphic?

This isn't a polymorphic encryption.

You can modify it to get a different output every time and call it polymorphic 😝
trying to use this to encrypt and decrypt tibia packets.

I set up a test app to just test the functions.
I do Like this.

Key = New UInteger(5) {}
Packet = New UInteger(10) {}

For i As Integer = 0 To 5
Key(i) = i
Next
For i As Integer = 5 To 10
Packet(i) = i
Next
XTea.code(Packet, Key)

This get me overflowed everytime.

EDIT:
Same thing with only string. and I use encrypt.
Very nice work as always bro :)
(Dec 24, 2010 03:05 PM)klusbert Wrote:  trying to use this to encrypt and decrypt tibia packets.
Spoiler (Click to View)
This get me overflowed everytime.

EDIT:
Same thing with only string. and I use encrypt.

Disable overflow checking :
[img]http://ploader.net/files/49d66822732cf18423e5095f9fdc94a5.gif[/img]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by cjackNov 12, 2015 04:28 AM 15 913 Nov 12, 2015 04:28 AM
Last Post: freed0m
[.NET] by ๖ۣۜMrRootMar 4, 2015 07:07 AM 4 219 Mar 4, 2015 07:07 AM
Last Post: ๖ۣۜMrRoot
[.NET] by rweed1Feb 5, 2015 04:27 PM 10 839 Feb 5, 2015 04:27 PM
Last Post: SIM-1456245