Fehler beim übersetzen mit case

  • VB.NET

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von picoflop.

    Fehler beim übersetzen mit case

    Hallo Leute!
    Ich arbeite seit letztens an einem crypter, der zuerst den Text mit Rijndael und dann zusätzlich nochmal mit einem Case verschlüsselt. hier der aktuelle code:

    VERSCHLÜSSELN:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim rd As New RijndaelManaged
    2. Dim md5 As New MD5CryptoServiceProvider
    3. Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(PasswordToCrypt.Text))
    4. md5.Clear()
    5. rd.Key = key
    6. rd.GenerateIV()
    7. Dim iv() As Byte = rd.IV
    8. Dim ms As New MemoryStream
    9. ms.Write(iv, 0, iv.Length)
    10. Dim cs As New CryptoStream(ms, rd.CreateEncryptor, CryptoStreamMode.Write)
    11. Dim data() As Byte = System.Text.Encoding.UTF8.GetBytes(TextToCrypt.Text)
    12. cs.Write(data, 0, data.Length)
    13. cs.FlushFinalBlock()
    14. Dim encdata() As Byte = ms.ToArray()
    15. TextToCrypt.Text = ""
    16. TextToCrypt.Text = Convert.ToBase64String(encdata)
    17. cs.Close()
    18. rd.Clear()
    19. UseCase = 1
    20. If UseCase = 1 Then
    21. Dim str As String, Newstr As String = Nothing
    22. str = TextToCrypt.Text
    23. For Each StrText As String In str
    24. Select Case True
    25. 'chars
    26. Case StrText = "a"
    27. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 1)
    28. .
    29. .
    30. .
    31. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 25)
    32. Case StrText = "z"
    33. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 26)
    34. 'nums
    35. Case StrText = "1"
    36. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 27)
    37. .
    38. .
    39. .
    40. Case StrText = "9"
    41. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 35)
    42. Case StrText = "0"
    43. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 36)
    44. 'UPER CASE
    45. Case StrText = "A"
    46. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 37)
    47. .
    48. .
    49. .
    50. .
    51. Case StrText = "Z"
    52. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 62)
    53. 'Secial Char
    54. Case StrText = "½"
    55. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 63)
    56. .
    57. .
    58. .
    59. Case StrText = "|"
    60. StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 98)
    61. Case True
    62. For I = 0 To X.Length - 1
    63. StrText = StrText.Replace(V.ElementAt(I), _
    64. X.ElementAt(I))
    65. Next
    66. End Select
    67. Newstr &= StrText
    68. Next
    69. TextToCrypt.Text = Newstr
    70. UseCase = 0
    71. End If



    ENTSCHLÜSSELN:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim str As String, Newstr As String = Nothing
    2. str = TextToDecrypt.Text
    3. For Each StrText As String In str
    4. Select Case True
    5. 'chars
    6. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 1)
    7. StrText = "a"
    8. .
    9. .
    10. .
    11. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 26)
    12. StrText = "z"
    13. 'nums
    14. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 27)
    15. StrText = "1"
    16. .
    17. .
    18. .
    19. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 35)
    20. StrText = "9"
    21. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 36)
    22. StrText = "0"
    23. 'UPER CASE
    24. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 37)
    25. StrText = "A"
    26. .
    27. .
    28. .
    29. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 62)
    30. StrText = "Z"
    31. 'Secial Char
    32. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 63)
    33. StrText = "½"
    34. .
    35. .
    36. .
    37. Case StrText = ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\CrypterData\EnDeCase.dll", 98)
    38. StrText = "|"
    39. Case True
    40. For I = 0 To X.Length - 1
    41. StrText = StrText.Replace(V.ElementAt(I), _
    42. X.ElementAt(I))
    43. Next
    44. End Select
    45. Newstr &= StrText
    46. Next
    47. TextToDecrypt.Text = Newstr
    48. Dim rd As New RijndaelManaged
    49. Dim rijndaelIvLength As Integer = 16
    50. Dim md5 As New MD5CryptoServiceProvider
    51. Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(PasswordToDecrypt.Text))
    52. md5.Clear()
    53. Try
    54. Dim encdata() As Byte = Convert.FromBase64String(TextToDecrypt.Text)
    55. Dim ms As New MemoryStream(encdata)
    56. Dim iv(15) As Byte
    57. ms.Read(iv, 0, rijndaelIvLength)
    58. rd.IV = iv
    59. rd.Key = key
    60. Try
    61. Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read)
    62. Dim data(ms.Length - rijndaelIvLength) As Byte
    63. Dim i As Integer = cs.Read(data, 0, data.Length)
    64. TextToDecrypt.Text = System.Text.Encoding.UTF8.GetString(data, 0, i)
    65. cs.Close()
    66. rd.Clear()
    67. Catch CryptographicExceptionParameter As CryptographicException
    68. MessageBox.Show("Decrypting Process failure!" + vbCrLf + "(Password incorrect or wrong type?)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    69. End Try
    70. Catch formatExceptionParameter As FormatException
    71. MessageBox.Show("Decrypting Process failure!" + vbCrLf + "(Password incorrect or wrong type?)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    72. End Try



    EnDeCase.dll:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. z
    2. y
    3. x
    4. w
    5. v
    6. u
    7. t
    8. s
    9. r
    10. q
    11. p
    12. o
    13. n
    14. m
    15. l
    16. k
    17. j
    18. i
    19. h
    20. g
    21. f
    22. e
    23. d
    24. c
    25. b
    26. a
    27. 0
    28. 9
    29. 8
    30. 7
    31. 6
    32. 5
    33. 4
    34. 3
    35. 2
    36. 1
    37. Z
    38. Y
    39. X
    40. W
    41. V
    42. U
    43. T
    44. S
    45. R
    46. Q
    47. P
    48. O
    49. N
    50. M
    51. L
    52. K
    53. J
    54. I
    55. H
    56. G
    57. F
    58. E
    59. D
    60. C
    61. B
    62. A
    63. |
    64. _
    65. :
    66. ;
    67. <
    68. ~
    69. ¨
    70. ´
    71. \
    72. }
    73. ]
    74. [
    75. {
    76. $
    77. £
    78. @
    79. §
    80. -
    81. .
    82. ,
    83. >
    84. *
    85. ^
    86. `
    87. ?
    88. =
    89. )
    90. (
    91. /
    92. &
    93. %
    94. ¤
    95. #
    96. !
    97. ½



    auf die function ReadLine möchte ich jetzt nicht weiter eingehen, diese steht woanders.
    Das verschlüsseln klappt fehlerlos.
    Beim entschlüsseln tritt jedoch der fehler auf, dass im case als EINZIGES das z zu einem a übersetzt wird. der rest wird nicht übersetzt. --> fehler beim entschlüsseln mit rijndael.
    kann mir einer beim finden des fehlers helfen?
    danke im vorraus!

    //EDIT: Überall, wo im code 3zeilen lang . steht, ist die reihenfolge klar, und es wurde wegen max. 15000 zeichen gekürzt.
    1. Ist die weitere Verschlüsselung eines mit AES verschlüsselten Textes unsinnig. Um so unsinniger, wenn ein einfacher Zeichentauscher verwendet wird.
    2. Ist die Verwendung von Select-Case für eine Zeichenvertauschung aber sowas von unschön ... Fleiß: 9/10, Hirnschmalz: 0/10

    EDIT:
    3. Die VERÄNDERUNG der Iterationsvariable IN der Schleife ist Mega-Murks