740
社区成员
发帖
与我相关
我的任务
分享
///////////////////////////////////////////////////////////////////
// 加密
// 传入参数 string str_password
///////////////////////////////////////////////////////////////////
int i,intLen
int intN
string strP
string strPass
intN = 20
strP = upper(str_password)
intLen = len(strP)
if intLen < intN then
strP = strP + space(intLen)
end if
strPass = ''
for i = 1 to intN
strPass = strPass + char(asc(mid(strP,i,1))+1) // 将字符转换成ASCII加1,然后再转成字符
next
return strPass
////////////////////////////////////////////////////////////////
// 解密
// 传入参数:string sPassWord
///////////////////////////////////////////////////////////////////
string sOldPass
integer i
sOldPass=''
for i=1 to 20
sOldPass = sOldPass+char(asc(upper(mid(sPassWord,i,1)))-1)
next
return sOldPass
// 这是C#解码代码,如果传入参数s为中文,结果就是错的
StringBuilder sPassWord = new StringBuilder();
ASCIIEncoding ascii = new ASCIIEncoding();
Byte[] encodedBytes = ascii.GetBytes(s.Trim ());
int i=0;
foreach (Byte b in encodedBytes)
{
i++;
sPassWord.Append((char)(b - 1));
if (i >= 20)
break;
}
sPassWord.Replace("\0", "");
return sPassWord.ToString();