这次是加密的算法有错,但我不知道错在哪
'CHIPER.CLS
Option Explicit
Private mstrKey As String
Private mstrText As String
'---.KeyString
'A string(key) used in eintCryption and decryption
Public Property Let KeyString(ByVal strKey As String)
mstrKey = strKey
Initialize
End Property
'---.Text
'Write text to be eintCrypted or decrypted
Public Property Let Text(ByVal strText As String)
mstrText = strText
End Property Public Property Get EncryptedOrDecrypted_Text()
EncryptedOrDecrypted_Text = mstrText
End Property
'---.DoXor
'Exclusive-or method to encrypt or decrypt
Public Sub DoXor()
Dim IngC As Long
Dim IntB As Long
Dim ingN As Long
For ingN = 1 To Len(mstrText)
IngC = Asc(Mid(mstrText, ingN, 1))
IntB = Int(Rnd * 256)
Mid(mstrText, ingN, 1) = Chr(IngC Xor IntB)
Next ingN
End Sub
'---.Stretch
'Convert any string to a printable,displayable string
Public Sub Stretch()
Dim IngC As Long
Dim ingN As Long
Dim IngJ As Long
Dim IngK As Long
Dim IngA As Long
Dim strB As String
IngA = Len(mstrText)
strB = Space(IngA + (IngA + 2) \ 3)
For ingN = 1 To IngA
IngC = Asc(Mid(mstrText, ingN, 1))
IngJ = IngJ + 1
Mid(strB, IngJ, 1) = Chr((IngC And 63) + 59)
Select Case ingN Mod 3
Case 1
IngK = IngK Or ((IngC \ 64) * 16)
Case 2
IngK = IngK Or ((IngC \ 64) * 4)
Case 0
IngK = IngK Or (IngC \ 64)
IngJ = IngJ + 1
Mid(strB, IngJ, 1) = Chr(IngK + 59)
IngK = 0
End Select
Next ingN
If IngA Mod 3 Then
IngJ = IngJ + 1
Mid(strB, IngJ, 1) = Chr(IngK + 59)
End If
mstrText = strB
End Sub
'---.Shrink
'Inverse of the Stretch method;
'result can contain any of the 256-byte values
Public Sub Shrink()
Dim IngC As Long
Dim IngD As Long
Dim IngE As Long
Dim IngA As Long
Dim IngB As Long
Dim ingN As Long
Dim IngJ As Long
Dim IngK As Long
Dim strB As String
IngA = Len(mstrText)
IngB = IngA - 1 - (IngA - 1) \ 4
strB = Space(IngB)
For ingN = 1 To IngB
IngJ = IngJ + 1
IngC = Asc(Mid(mstrText, IngJ, 1)) - 59
Select Case ingN Mod 3
Case 1
IngK = IngK + 4
If IngK > IngA Then IngK = IngA
IngE = Asc(Mid(mstrText, IngK, 1)) - 59
IngD = ((IngE \ 16) And 3) * 64
Case 2
IngD = ((IngE \ 4) And 3) * 64
Case 0
IngD = (IngE And 3) * 64
IngJ = IngJ + 1
End Select
Mid(strB, ingN, 1) = Chr(IngC Or IngD)
Next ingN
mstrText = strB
End Sub
'Initializes random numbers using the key string
Private Sub Initialize()
Dim ingN As Long
Randomize Rnd(-1)
For ingN = 1 To Len(mstrKey)
Randomize Rnd(-Rnd * Asc(Mid(mstrKey, ingN, 1)))
Next ingN
End Sub
加密 “This is a text" , 密匙为"ABC" 是为 iG;;;;K<;;D<q;;;;;;
但 解密后就变成了 “ _`IdO”
'CHIPER.CLS
Option Explicit
Private mstrKey As String
Private mstrText As String
'---.KeyString
'A string(key) used in eintCryption and decryption
Public Property Let KeyString(ByVal strKey As String)
mstrKey = strKey
Initialize
End Property
'---.Text
'Write text to be eintCrypted or decrypted
Public Property Let Text(ByVal strText As String)
mstrText = strText
End Property Public Property Get EncryptedOrDecrypted_Text()
EncryptedOrDecrypted_Text = mstrText
End Property
'---.DoXor
'Exclusive-or method to encrypt or decrypt
Public Sub DoXor()
Dim IngC As Long
Dim IntB As Long
Dim ingN As Long
For ingN = 1 To Len(mstrText)
IngC = Asc(Mid(mstrText, ingN, 1))
IntB = Int(Rnd * 256)
Mid(mstrText, ingN, 1) = Chr(IngC Xor IntB)
Next ingN
End Sub
'---.Stretch
'Convert any string to a printable,displayable string
Public Sub Stretch()
Dim IngC As Long
Dim ingN As Long
Dim IngJ As Long
Dim IngK As Long
Dim IngA As Long
Dim strB As String
IngA = Len(mstrText)
strB = Space(IngA + (IngA + 2) \ 3)
For ingN = 1 To IngA
IngC = Asc(Mid(mstrText, ingN, 1))
IngJ = IngJ + 1
Mid(strB, IngJ, 1) = Chr((IngC And 63) + 59)
Select Case ingN Mod 3
Case 1
IngK = IngK Or ((IngC \ 64) * 16)
Case 2
IngK = IngK Or ((IngC \ 64) * 4)
Case 0
IngK = IngK Or (IngC \ 64)
IngJ = IngJ + 1
Mid(strB, IngJ, 1) = Chr(IngK + 59)
IngK = 0
End Select
Next ingN
If IngA Mod 3 Then
IngJ = IngJ + 1
Mid(strB, IngJ, 1) = Chr(IngK + 59)
End If
mstrText = strB
End Sub
'---.Shrink
'Inverse of the Stretch method;
'result can contain any of the 256-byte values
Public Sub Shrink()
Dim IngC As Long
Dim IngD As Long
Dim IngE As Long
Dim IngA As Long
Dim IngB As Long
Dim ingN As Long
Dim IngJ As Long
Dim IngK As Long
Dim strB As String
IngA = Len(mstrText)
IngB = IngA - 1 - (IngA - 1) \ 4
strB = Space(IngB)
For ingN = 1 To IngB
IngJ = IngJ + 1
IngC = Asc(Mid(mstrText, IngJ, 1)) - 59
Select Case ingN Mod 3
Case 1
IngK = IngK + 4
If IngK > IngA Then IngK = IngA
IngE = Asc(Mid(mstrText, IngK, 1)) - 59
IngD = ((IngE \ 16) And 3) * 64
Case 2
IngD = ((IngE \ 4) And 3) * 64
Case 0
IngD = (IngE And 3) * 64
IngJ = IngJ + 1
End Select
Mid(strB, ingN, 1) = Chr(IngC Or IngD)
Next ingN
mstrText = strB
End Sub
'Initializes random numbers using the key string
Private Sub Initialize()
Dim ingN As Long
Randomize Rnd(-1)
For ingN = 1 To Len(mstrKey)
Randomize Rnd(-Rnd * Asc(Mid(mstrKey, ingN, 1)))
Next ingN
End Sub
加密 “This is a text" , 密匙为"ABC" 是为 iG;;;;K<;;D<q;;;;;;
但 解密后就变成了 “ _`IdO”