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

.NET 

VB 2010 Encyrpter XTEA

hello. I have a problem. I'm trying to do Encrypter XTEA. Borrowed code from the user d3c0mpil3r. I can not understand it. code:
Code
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

I can not call the function. The value of v is the text that is to be encrypted? The value of k is the key? How do these data call?
Since the function doesn't Return anything, you will have to do something like this :

Dim Myvalue as Uinteger
Myvalue = code(123,456)

Also please do refer to former replies :

https://hackforums.net/showthread.php?ti...pid8555658
https://hackforums.net/showthread.php?ti...pid8566970
Assert failure(PID 10704 [0x000029d0], Thread: 10960 [0x2ad0]): pBuffer != NULL
its not the main function

Public Function Encrypt(ByVal input As String) As String
...
Public Function Decrypt(ByVal Data As String) As String
...
thanks. And can someone explain to me how to make it work? How substitute data, how to call a function, where the sets own key, where he sets the text to encrypt? I am a beginner. I became interested in data encryption. I would like to know the code of the user d3c0mpil3r. Full code:
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
Dim X As New XTea("Pass")
Dim Enc = X.Encrypt("String")
MsgBox(X.Dcrypt(Enc))
WOW, thanks. I just have a problem. What do I do?
Quote:'Public Sub New(password As String)' in designer-generated type 'XTEA_Encryption.Form1' should call InitializeComponent method.

Quote:'Form1' is a type in 'XTEA_Encryption' and cannot be used as an expression.

https://hackforums.net/showthread.php?tid=815420

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim X As New XTea("Pass")
Dim Enc = X.Encrypt("String")
MsgBox(X.Dcrypt(Enc))
...
Public Class XTea
...
End Class
End Class
awesome, aww :3 why I have Overflow error ?
cant guess read the replys in his thread
I read and I cant find. The question no answer. I know that the key has a length of 6 - 16 characters.

my code:
Code
Private Sub xtea_button_Click(sender As System.Object, e As System.EventArgs) Handles xtea_button.Click
      Dim X As New XTea("1234567890") 'key
      Dim Enc = X.Encrypt("qwertyuiop")
      output.Text = X.Encrypt(Enc)
    End Sub

Overflow is:
Code
y += (z << 4 Xor z >> 5) + z Xor sum + k(sum And 3)
or
Code
sum += delta

I cant fix it...😧
project properties...advanced compiling options...check on remove integer overflow control.

[Image: Lymnm1L.jpg]

thanks thanks thanks :D you are pro :D
if u just read the replys https://hackforums.net/showthread.php?ti...pid8566970
oh, I noticed just now ... sorry for the problem. I thought this signature . a big thank you gentlemen for a very good help. I bet you a beer :D . I have one question . the entire script returns the encrypted text in strange characters. is the ability to do that drew in numbers ? :D eg introduce the key, as the text I have " 1234567890 " . text goes through the script and returns the encrypted me in numbers . is it possible?
thats all the idea of encrypt text > strange characters


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by SkillfulJan 20, 2012 04:48 PM 5 189 Jan 20, 2012 04:48 PM
Last Post: webdev77
[.NET] by d3c0mpil3rOct 8, 2011 05:49 AM 26 1,245 Oct 8, 2011 05:49 AM
Last Post: Stenography
[.NET] by 0vanAug 29, 2011 08:15 AM 3 75 Aug 29, 2011 08:15 AM
Last Post: 0van