Domino 加密密码 与C#版本对应

本文介绍了一种使用VBA编写的简单加密和解密方法。通过修改字符的ASCII值并结合特定的异或运算实现加密过程,同时对一些特殊字符进行了转义处理以确保加密后的字符串可以作为文件名使用。解密过程则通过逆向操作恢复原始字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Public Function Encrypt(strPWtoEncrypt As String) As String
Dim strPword As String
Dim bytCount As Byte
Dim intTemp As Integer

For bytCount = 1 To Len(strPWtoEncrypt)
intTemp = Asc(Mid(strPWtoEncrypt, bytCount, 1))
If bytCount Mod 2 = 0 Then
intTemp = intTemp - bytEncrypt
Else
intTemp = intTemp + bytEncrypt
End If

intTemp = intTemp Xor (10 - bytEncrypt)
strPword = strPword & Chr$(intTemp)
Next bytCount
'Some words cannot be used as file name
Encrypt = strPword
Encrypt = Replace(strPword, "\", "{01}")
Encrypt = Replace(strPword, "/", "{02}")
Encrypt = Replace(strPword, ":", "{03}")
Encrypt = Replace(strPword, "*", "{04}")
Encrypt = Replace(strPword, "?", "{05}")
Encrypt = Replace(strPword, """", "{06}")
Encrypt = Replace(strPword, "<", "{07}")
Encrypt = Replace(strPword, ">", "{08}")
Encrypt = Replace(strPword, "|", "{09}")

End Function
Public Function Decrypt(strPWtoDecrypt As String) As String
Dim strPword As String
Dim bytCount As Byte
Private Const bytEncrypt = 5

Dim intTemp As Integer

strPWtoDecrypt = Replace(strPWtoDecrypt, "{01}", "\")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{02}", "/")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{03}", ":")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{04}", "*")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{05}", "?")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{06}", """")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{07}", "<")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{08}", ">")
strPWtoDecrypt = Replace(strPWtoDecrypt, "{09}", "|")

For bytCount = 1 To Len(strPWtoDecrypt)
intTemp = Asc(Mid(strPWtoDecrypt, bytCount, 1)) Xor (10 - bytEncrypt)
If bytCount Mod 2 = 0 Then
intTemp = intTemp + bytEncrypt
Else
intTemp = intTemp - bytEncrypt
End If

strPword = strPword & Chr$(intTemp)
Next bytCount

Decrypt = strPword
End Function

转载于:https://www.cnblogs.com/blackbean/archive/2011/07/16/2108191.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值