Я новичок в этой области шифрования, а также изучаю проницательный код инженеров.Шифрование работает, но я хотел бы расшифровать, я не уверен, что или как начать
Существует класс PasswordEncryption, который выглядит следующим образом:
Public Class PasswordEncryption
Public Shared arrBase64EncMap(64) As String
Public Shared arrBase64DecMap(127) As Integer
Const BASE_64_MAP_INIT As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Public Shared Function EncryptionPassword() As String
Return "F2oWrB4sA3feEh1tz"
End Function
Public Shared Function simpleXor(ByVal strIn As String, ByVal strKey As String) As String
Dim iInIndex As Integer
Dim iKeyIndex As Integer
Dim strReturn As String
If Len(strIn) = 0 Or Len(strKey) = 0 Then
simpleXor = ""
Exit Function
End If
iInIndex = 1
iKeyIndex = 1
strReturn = ""
'** Step through the plain text source XORing the character at each point with the next character in the key **
'** Loop through the key characters as necessary **
Do While iInIndex <= Len(strIn)
strReturn = strReturn & Chr(Asc(Mid(strIn, iInIndex, 1)) Xor Asc(Mid(strKey, iKeyIndex, 1)))
iInIndex = iInIndex + 1
If iKeyIndex = Len(strKey) Then iKeyIndex = 0
iKeyIndex = iKeyIndex + 1
Loop
simpleXor = strReturn
End Function
Public Shared Function base64Encode(ByVal strPlain As String) As String
Dim iLoop As Integer
Dim iBy3 As Integer
Dim strReturn As String
Dim iIndex As Integer
Dim iFirst As Integer
Dim iSecond As Integer
Dim iiThird As Integer
If strPlain.Length = 0 Then
base64Encode = ""
Exit Function
End If
'** Set up Base64 Encoding and Decoding Maps for when we need them **
For iLoop = 0 To Len(BASE_64_MAP_INIT) - 1
arrBase64EncMap(iLoop) = Mid(BASE_64_MAP_INIT, iLoop + 1, 1)
Next
For iLoop = 0 To Len(BASE_64_MAP_INIT) - 1
arrBase64DecMap(Asc(arrBase64EncMap(iLoop))) = iLoop
Next
'** Work out rounded down multiple of 3 bytes length for the unencoded text **
iBy3 = (strPlain.Length \ 3) * 3
strReturn = ""
'** For each 3x8 byte chars, covert them to 4x6 byte representations in the Base64 map **
iIndex = 1
Do While iIndex <= iBy3
iFirst = Asc(Mid(strPlain, iIndex + 0, 1))
iSecond = Asc(Mid(strPlain, iIndex + 1, 1))
iiThird = Asc(Mid(strPlain, iIndex + 2, 1))
strReturn = strReturn & arrBase64EncMap((iFirst \ 4) And 63)
strReturn = strReturn & arrBase64EncMap(((iFirst * 16) And 48) + ((iSecond \ 16) And 15))
strReturn = strReturn & arrBase64EncMap(((iSecond * 4) And 60) + ((iiThird \ 64) And 3))
strReturn = strReturn & arrBase64EncMap(iiThird And 63)
iIndex = iIndex + 3
Loop
'** Handle any trailing characters not in groups of 3 **
'** Extend to multiple of 3 characters using = signs as per RFC **
If iBy3 < strPlain.Length Then
iFirst = Asc(Mid(strPlain, iIndex + 0, 1))
strReturn = strReturn & arrBase64EncMap((iFirst \ 4) And 63)
If (strPlain.Length Mod 3) = 2 Then
iSecond = Asc(Mid(strPlain, iIndex + 1, 1))
strReturn = strReturn & arrBase64EncMap(((iFirst * 16) And 48) + ((iSecond \ 16) And 15))
strReturn = strReturn & arrBase64EncMap((iSecond * 4) And 60)
Else
strReturn = strReturn & arrBase64EncMap((iFirst * 16) And 48)
strReturn = strReturn & "="
End If
strReturn = strReturn & "="
End If
'** Return the encoded result string **
base64Encode = strReturn
End Function
End Class
У меня есть простая форма, котораяимеет две кнопки Encrypt и Decrypt и пару текстовых полей.
Событие нажатия кнопки шифрования выполняет следующее
Private Sub btnEncrypt_Click(sender As Object, e As EventArgs) Handles btnEncrypt.Click
If tbxPassword.Text IsNot Nothing Then
Dim PasswordEncryption As PasswordEncryption = New PasswordEncryption()
Dim strXOR As String = PasswordEncryption.simpleXor(Strings.Left(tbxPassword.Text.ToString().Trim, 20), PasswordEncryption.EncryptionPassword)
Dim encryptedPassword = PasswordEncryption.base64Encode(strXOR)
tbxResult.Text = encryptedPassword
Else
MessageBox.Show("No action can be performed")
End If
End Sub
У меня есть следующий код в кнопке дешифрования, но он не возвращает исходную строку
Private Sub btnDecrypt_Click(sender As Object, e As EventArgs) Handles btnDecrypt.Click
If tbxPassword.Text IsNot Nothing Then
Dim PasswordEncryption As PasswordEncryption = New PasswordEncryption()
Dim strXOR As String = PasswordEncryption.simpleXor(Strings.Left(tbxPassword.Text.ToString().Trim, 20), PasswordEncryption.EncryptionPassword)
Dim decryptedPassword = PasswordEncryption.base64Encode(strXOR)
tbxResult.Text = decryptedPassword
Else
MessageBox.Show("No action can be performed")
End If
Что мне нужно реализовать, чтобы вернуть исходную строку.Спасибо, ребята!