-
-
Save vivekwebm2020/44d46ae39e7d31bcbf049e29ea71153f to your computer and use it in GitHub Desktop.
Encrypt And Decrypt String by VBScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Call EncryptTool | |
Call DecryptTool | |
'------------------------ | |
'【 加密字符串 】 | |
'------------------------ | |
Private Function Encrypt(Plaintext) | |
Const offset = 10 | |
Const minAsc = 33 | |
Const maxAsc = 126 | |
Dim Ciphertext | |
Randomize | |
Ciphertext = Ciphertext & Chr(Int((maxAsc-minAsc+1)*Rnd+minAsc)) | |
Ciphertext = Ciphertext & Chr(Int((maxAsc-minAsc+1)*Rnd+minAsc)) | |
For i=1 To Len(Plaintext)*2 | |
If i mod 2 = 0 Then | |
newAsc = Asc(Mid(Plaintext,i/2,1)) - offset | |
If newAsc < minAsc Then | |
newAsc = newAsc + maxAsc - minAsc + 1 | |
End If | |
Ciphertext = Ciphertext & Chr(newAsc) | |
' MsgBox Asc(Mid(Plaintext,i/2,1)) & " -> " & newAsc | |
Else | |
Ciphertext = Ciphertext & Chr(Int((maxAsc-minAsc+1)*Rnd+minAsc)) | |
' MsgBox "Rnd:" & Chr(Int((maxAsc-minAsc+1)*Rnd+minAsc)) | |
End If | |
Next | |
Ciphertext = Ciphertext & Chr(Int((maxAsc-minAsc+1)*Rnd+minAsc)) | |
Ciphertext = Ciphertext & Chr(Int((maxAsc-minAsc+1)*Rnd+minAsc)) | |
Encrypt = Ciphertext | |
End Function | |
Private Sub EncryptTool() | |
Plaintext = InputBox("在下面输入【明文】:","加密工具","") | |
Ciphertext = Encrypt(Plaintext) | |
InputBox "【明文】:" & Plaintext & vbNewLine & vbNewLine & "【密文】:如下","加密工具",Ciphertext | |
End Sub | |
'------------------------ | |
'【 解密字符串 】 | |
'------------------------ | |
Private Function Decrypt(Ciphertext) | |
Const offset = 10 | |
Const minAsc = 33 | |
Const maxAsc = 126 | |
If Len(Ciphertext) < 5 Then | |
Decrypt = "" | |
Exit Function | |
End If | |
Dim Plaintext | |
Ciphertext = Mid(Ciphertext,3,Len(Ciphertext)-4) | |
For i=2 To Len(Ciphertext) Step 2 | |
oldAsc = Asc(Mid(Ciphertext,i,1)) + offset | |
If oldAsc > maxAsc Then | |
oldAsc = oldAsc - maxAsc + minAsc - 1 | |
End If | |
Plaintext = Plaintext & Chr(oldAsc) | |
' MsgBox Asc(Mid(Ciphertext,i,1)) & " -> " & oldAsc | |
Next | |
Decrypt = Plaintext | |
End Function | |
Private Sub DecryptTool() | |
Ciphertext = InputBox("在下面输入【密文】:","解密工具","") | |
Plaintext = Decrypt(Ciphertext) | |
InputBox "【密文】:" & Ciphertext & vbNewLine & vbNewLine & "【明文】:如下","解密工具",Plaintext | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment