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

.NET 

[VB.NET] XTEA Encryption [Source]

Here's the XTEA functions in C#, in case someone needs them. For third party developers, you'll have to read they key from the clients memory.
Code
public unsafe static bool XteaEncrypt(ref byte[] buffer, ref int length, int index, uint[] key)
  {
    if (key == null)
    return false;

    int msgSize = length - index;

    int pad = msgSize % 8;
    if (pad > 0)
    {
    msgSize += (8 - pad);
    length = index + msgSize;
    }

    fixed (byte* bufferPtr = buffer)
    {
    uint* words = (uint*)(bufferPtr + index);

    for (int pos = 0; pos < msgSize / 4; pos += 2)
    {
    uint x_sum = 0, x_delta = 0x9e3779b9, x_count = 32;

    while (x_count-- > 0)
    {
    words[pos] += (words[pos+1] << 4 ^ words[pos+1] >> 5) + words[pos+1] ^ x_sum
    + key[x_sum & 3];
    x_sum += x_delta;
    words[pos+1] += (words[pos] << 4 ^ words[pos] >> 5) + words[pos] ^ x_sum
    + key[x_sum >> 11 & 3];
    }
    }
    }

    return true;
  }

  public unsafe static bool XteaDecrypt(ref byte[] buffer, ref int length, int index, uint[] key)
  {
    if (length <= index || (length - index) % 8 > 0 || key == null)
    return false;

    fixed (byte* bufferPtr = buffer)
    {
    uint* words = (uint*)(bufferPtr + index);
    int msgSize = length - index;

    for (int pos = 0; pos < msgSize / 4; pos += 2)
    {
    uint x_count = 32, x_sum = 0xC6EF3720, x_delta = 0x9E3779B9;

    while (x_count-- > 0)
    {
    words[pos + 1] -= (words[pos] << 4 ^ words[pos] >> 5) + words[pos] ^ x_sum
    + key[x_sum >> 11 & 3];
    x_sum -= x_delta;
    words[pos] -= (words[pos + 1] << 4 ^ words[pos + 1] >> 5) + words[pos + 1] ^ x_sum
    + key[x_sum & 3];
    }
    }
    }
    length = (int)(BitConverter.ToUInt16(buffer, index) + 2 + index);
    return true;
  }
dude,i fkin love you!
i was searching exactly for this!
Nice encryption :D I tried to make one once.. Faild.
Great share! thanks for this :D
No problem guys.
btwXXTEA Encryption (Click to View)
Wonderful job. Great man. You are just great :)
Very nice, I suggest you to make it polymorphic to make it even better.
im getting an error..

Code
Public Class Form1
    Dim xtea As XTea
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  xtea = New XTea(TextBox3.Text)
  TextBox2.Text = xtea.EncryptString(TextBox1.Text)
    End Sub

the error is...

Code
Error    1    'EncryptString' is not a member of 'XTea_Encryption.XTea'.

Any thoughts?
(Jul 16, 2011 07:57 AM)INFAМOUS Wrote:  im getting an error..

Code
Public Class Form1
    Dim xtea As XTea
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  xtea = New XTea(TextBox3.Text)
  TextBox2.Text = xtea.EncryptString(TextBox1.Text)
    End Sub

the error is...

Code
Error    1    'EncryptString' is not a member of 'XTea_Encryption.XTea'.

Any thoughts?

Their is no method named 'EncryptString'. Read the source!
You call it like:
Code
Dim x as new XTea("password")
x.Encrypt("data_to_encrypt")
Could you help me?
I have a file encrypted with XTEA and I have the key, but when I want to decrypt the file I ever get an Overflow Error :/
(Nov 13, 2010 06:42 AM)d3c0mpil3r Wrote:  XTEA is TEA's precursor.

XTEA = Extended TEA, so its a subsequent version, not a precursor ^^

Aside from that, it looks okay. Above poster gravedug, by the way.
Epic encryption..
Now trying how add this to my crypter and delete that gay detectable rc4.


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