Hack Forums
[.NET] VB 2010 Encyrpter XTEA - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] VB 2010 Encyrpter XTEA (/showthread.php?tid=4633644)

Pages: Pages 1 2


VB 2010 Encyrpter XTEA - trefl - Jan 12, 2015

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?


* - Aristocles - Jan 12, 2015

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?tid=815420&pid=8555658#pid8555658
https://hackforums.net/showthread.php?tid=815420&pid=8566970#pid8566970


* - Only3 - Jan 12, 2015

its not the main function

Public Function Encrypt(ByVal input As String) As String
...
Public Function Decrypt(ByVal Data As String) As String
...


* - trefl - Jan 13, 2015

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



* - Only3 - Jan 13, 2015

Dim X As New XTea("Pass")
Dim Enc = X.Encrypt("String")
MsgBox(X.Dcrypt(Enc))


* - trefl - Jan 13, 2015

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.




* - Only3 - Jan 13, 2015

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


* - trefl - Jan 13, 2015

awesome, aww :3 why I have Overflow error ?


* - Only3 - Jan 13, 2015

cant guess read the replys in his thread


* - trefl - Jan 13, 2015

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...😧


* - ScΛrƒΛc3_ - Jan 13, 2015

project properties...advanced compiling options...check on remove integer overflow control.


* - trefl - Jan 14, 2015

thanks thanks thanks :D you are pro :D


* - Only3 - Jan 14, 2015

if u just read the replys https://hackforums.net/showthread.php?tid=815420&pid=8566970#pid8566970


* - trefl - Jan 14, 2015

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?


* - Only3 - Jan 14, 2015

thats all the idea of encrypt text > strange characters