Click here to Skip to main content
14,326,161 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everybody,

I'm a newbie in VB.NET dev.

I get a code from a app and i would to test it alone: this is a xor decrypter.

Sometimes it works well and often it makes me cry with System.StackOverflowException from Public Sub New()

there is lot of line (0 to 999) like this
Me
.keyarr(0) = Chr(35) & Chr(54) & Chr(158) & Chr(43) & Chr(90) & Chr(143) & Chr(107) & Chr(172) & Chr(64) & Chr(150) & Chr(139) & Chr(199) & Chr(1) & Chr(26) & Chr(71) & Chr(51) & Chr(139) & Chr(187) & Chr(245) & Chr(212) & Chr(44) & Chr(232) & Chr(67) & Chr(93) & Chr(153) & Chr(206) & Chr(100) & Chr(212) & Chr(81) & Chr(159) & Chr(182) & Chr(47) & Chr(82) & Chr(11) & Chr(190) & Chr(147) & Chr(29) & Chr(57) & Chr(249) & Chr(106) & Chr(252) & Chr(32) & Chr(132) & Chr(180) & Chr(126) & Chr(152) & Chr(252) & Chr(231) & Chr(50) & Chr(243) & Chr(195) & Chr(185) & Chr(125) & Chr(129) & Chr(193) & Chr(50) & Chr(169) & Chr(202) & Chr(16) & Chr(81) & Chr(250) & Chr(231) & Chr(168) & Chr(158) & Chr(233) & Chr(195) & Chr(63) & Chr(24) & Chr(85) & Chr(161) & Chr(180) & Chr(169) & Chr(212) & Chr(190) & Chr(19) & Chr(180) & Chr(225) & Chr(122) & Chr(151) & Chr(209) & Chr(26) & Chr(164) & Chr(189) & Chr(83) & Chr(76) & Chr(166) & Chr(178) & Chr(180) & Chr(134) & Chr(253) & Chr(79) & Chr(123) & Chr(217) & Chr(156) & Chr(225) & Chr(164) & Chr(42) & Chr(1) & Chr(245) & Chr(78) & Chr(132) & Chr(58) & Chr(68) & Chr(138) & Chr(118) & Chr(236) & Chr(43) & Chr(35) & Chr(248) & Chr(103) & Chr(188) & Chr(57) & Chr(35) & Chr(218) & Chr(179) & Chr(129) & Chr(122) & Chr(249) & Chr(122) & Chr(17) & Chr(249) & Chr(201) & Chr(139) & Chr(120) & Chr(154) & Chr(19) & Chr(77) & Chr(20)


I think there is enough memory in my computer but i don't understand why i get this error, in the app there is no problem.
May i made a mistake in call function or something like that ?


Here the rest of the code:
Imports System

Module Module1




 Sub Main()

  Dim password As New Password

  password.EncryptedPassword = "2945D7F0F653C2EDFF"
  password.keyindex = 154



  password.getPassword()





 End Sub
 Public Class Password



  ' Keyarray, where the Xor-Keys are stored (To compile, use 0 to 999, for debugging use 0 to 25!)

  Const debugging As Boolean = True

  Private keyarr(0 To 999) As String

  ' Keyindex is used to find the Xor-Key in the Keyarray
  Public keyindex As Integer = 0

  ' Stores the encrypted password
  Public EncryptedPassword As String = ""

  ' Initiates the Keyarray





[Public Sub() ... End Sub] 0 to 999 lines ...





'This Function decrypts a password. The Function takes the Password and the KeyIndex. Encryption will be done with an Xor operation, and the result will be HEX-encoded, so the result is a string
  Private Function dec(ByVal Hex As String, ByVal keyindex As Integer) As String

   'lenght of the password
   Dim Lenght As Integer

   'The whole key, which will be used to encrypt the key. This key will be shorten to the needed lenght, and then be stored in the xorwith-variable.
   Dim Key As String

   'The result, as cleartext
   Dim Result As String = ""

   'Counter Variable
   Dim pwPosition As Integer

   'This is set to the numeric value of the character which is going to be xored against the key
   Dim intXorValueHex As Short

   'This is set to the numeric value of the character which is going to be xored against the Hex
   Dim intXorValueKey As Short

   'String for Temporary Use
   Dim TempStr As String

   'Integer for Temporary Use
   Dim TempInt As Integer

   Key = keyarr(keyindex)

   If Me.EncryptedPassword.Length > 0 Then



    Try
     'get the lenght of the password, it's half of the hex-lenght
     Lenght = Hex.Length / 2

     'As long as we are inside the Password
     For pwPosition = 1 To Lenght Step 1

      'Get the Char from the Key and the Hex as integer, at which position we are.
      intXorValueHex = CInt("&H" & Mid(Hex, pwPosition * 2 - 1, 2))
      intXorValueKey = Asc(Mid(Key, pwPosition, 1))

      'XOR this characters against eachother
      TempInt = (intXorValueHex Xor intXorValueKey)

      'Write the Char as Hex into the TempStr
      TempStr = Chr(TempInt)

      'Append the two chars of the Hex to the result-string
      Result &= TempStr
     Next
    Catch ex As System.Exception
     'MsgBox(ex.Message & vbNewLine & "Most possible, the Password was unencrypted")
    End Try

   End If



   Console.WriteLine(Result)

   Return Result

  End Function


  Public Function getPassword() As String
   ' Function which returns the Password as string
   Return Me.dec(EncryptedPassword, keyindex)
  End Function


 End Class


End Module


Thanks for your help



Best Regards



Samuel
Posted
Updated 27-Apr-10 2:11am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

You know, the debugger is the best friend.
:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

lol, the debbuger say nothing

i give just 'System.StackOverflowException'

sometimes the program works when i set keyindex to 0 and i rebuild and restart then i should recompile...
it is a clue ?

thanks
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100