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

.NET 

[VB.NET] XTEA Encryption [Source]

(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.
Very nice work as always bro :)
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;
  }
Nice encryption :D I tried to make one once.. Faild.
Very nice, I suggest you to make it polymorphic to make it even better.
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 :/
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