ASP取rc4 为什么不全 输入的明文字符串是:解密输出的字符串是解密输出的字符串是 加密后的密文字符串:綗
发布网友
发布时间:2023-04-28 20:34
我来回答
共2个回答
热心网友
时间:2023-10-30 03:44
这是全部的代码 那位老师帮忙改下
另外数据库调用时怎样设置编码??
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</HEAD>
<%
'key="sdfjal;dfjaoiejojfafnsanf;aufweijoanfanfaieufowejrwnf;aupagyuweranfsajfagfuoag"
Function EnCrypt(plaintxt, psw)
Dim key(255)
Dim sbox(255)
dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher
dim tempSwap
dim b
intLength = len( psw)
For a = 0 To 255
key(a) = asc(mid( psw, (a mod intLength)+1, 1))
'key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
sbox(a) = a
next
b = 0
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempSwap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempSwap
Next
i = 0
j = 0
For a = 1 To Len(plaintxt)
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
' k = sbox((sbox(i) + (sbox(j) Mod 256)) Mod 256)
k = sbox((sbox(i) + sbox(j)) Mod 256)
cipherby = asc(Mid(plaintxt, a, 1)) Xor k
'cipher = cipher & ""&cipherby&";"
cipher = cipher & Chr(cipherby)
Next
EnCrypt = cipher
End Function
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
plaintext=request.form("plaintext")
response.write "<br>输入的明文字符串是:"&plaintext
cryptext=EnCrypt(plaintext,"QQ:123581766")
response.write "<br>加密后的密文字符串:" &cryptext
decryptext=EnCrypt(cryptext,"QQ:123581766")
'decryptext= server.urlencode(DeCrypt(cryptext,key))
response.write "<br>解密输出的字符串是:" &decryptext
end if
%>
<title>RC4加密算法模拟</title>
<FORM METHOD="POST" ACTION="rc4.asp">
<P>请输入需要加密的明文:<INPUT TYPE="text" NAME="plaintext" SIZE="20">
</P>
<P>
<INPUT TYPE="submit" VALUE="进行加密" NAME="B1">
<INPUT TYPE="reset" VALUE="重新输入" NAME="B2"></P>
</FORM>
热心网友
时间:2023-10-30 03:45
编码不一样。。。网页顶部设置编码。。要是查询数据库得出来的顺带给查询在定义一下编码。。
热心网友
时间:2023-10-30 03:44
这是全部的代码 那位老师帮忙改下
另外数据库调用时怎样设置编码??
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</HEAD>
<%
'key="sdfjal;dfjaoiejojfafnsanf;aufweijoanfanfaieufowejrwnf;aupagyuweranfsajfagfuoag"
Function EnCrypt(plaintxt, psw)
Dim key(255)
Dim sbox(255)
dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher
dim tempSwap
dim b
intLength = len( psw)
For a = 0 To 255
key(a) = asc(mid( psw, (a mod intLength)+1, 1))
'key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
sbox(a) = a
next
b = 0
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempSwap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempSwap
Next
i = 0
j = 0
For a = 1 To Len(plaintxt)
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
' k = sbox((sbox(i) + (sbox(j) Mod 256)) Mod 256)
k = sbox((sbox(i) + sbox(j)) Mod 256)
cipherby = asc(Mid(plaintxt, a, 1)) Xor k
'cipher = cipher & ""&cipherby&";"
cipher = cipher & Chr(cipherby)
Next
EnCrypt = cipher
End Function
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
plaintext=request.form("plaintext")
response.write "<br>输入的明文字符串是:"&plaintext
cryptext=EnCrypt(plaintext,"QQ:123581766")
response.write "<br>加密后的密文字符串:" &cryptext
decryptext=EnCrypt(cryptext,"QQ:123581766")
'decryptext= server.urlencode(DeCrypt(cryptext,key))
response.write "<br>解密输出的字符串是:" &decryptext
end if
%>
<title>RC4加密算法模拟</title>
<FORM METHOD="POST" ACTION="rc4.asp">
<P>请输入需要加密的明文:<INPUT TYPE="text" NAME="plaintext" SIZE="20">
</P>
<P>
<INPUT TYPE="submit" VALUE="进行加密" NAME="B1">
<INPUT TYPE="reset" VALUE="重新输入" NAME="B2"></P>
</FORM>
热心网友
时间:2023-10-30 03:45
编码不一样。。。网页顶部设置编码。。要是查询数据库得出来的顺带给查询在定义一下编码。。