用ASP分别编写一个实现加密和解密功能的页面
作业求问.......用ASP分别编写一个实现加密和解密功能的页面,用户在加密页面输入明文字符串后可以得到经过加密的密文,将该密文输入解密页面后可以还原成用户输入的明文...
作业求问.......用ASP分别编写一个实现加密和解密功能的页面,用户在加密页面输入明文字符串后可以得到经过加密的密文,将该密文输入解密页面后可以还原成用户输入的明文
展开
2个回答
2014-01-13
展开全部
是不是MD5加密?如果是MD5加密,加密后是不可能解密的。而用ASP加密的话,一旦别人知道了算法的话,基本上就没有加密型可言了
下面是ASP加密
Function.asp
<%
Rem =================================================================
Rem = 函数文件:Function.asp
Rem = 测试文件:TestEncrypt.asp,Encryptpass.asp
Rem = 说明:Encrypt_PRO加密函数,Decrypt_PRO解密函数
Rem = 代码算法需要重写,可能知道的人多了就不太安全了。
=================================================================
Public Const sDefaultWHEEL1 = "ABCDEFGHIJKLMNOPQRSTVUWXYZ_1234567890qwertyuiopasd!@#$%^&*(),. ~`-=\?/’""fghjklzxcvbnm<>;"
Public Const sDefaultWHEEL2 = "IWEHJKTLZVOPFG_1234567890qwerBNMQRYUASDXCfghjklzxc ~`-=\?/’""!@#$%^&*(),.vbnm<>;tyuiopasd"
Function Encrypt_PRO(sINPUT , sPASSWORD )
Dim sWHEEL1, sWHEEL2
Dim k, c, i
Dim sRESULT
sWHEEL1 = sDefaultWHEEL1: sWHEEL2 = sDefaultWHEEL2
ScrambleWheels sWHEEL1, sWHEEL2, sPASSWORD
sRESULT = ""
For i = 1 To Len(sINPUT)
c = Mid(sINPUT, i, 1)
k = InStr(1, sWHEEL1, c)
If k > 0 Then
sRESULT = sRESULT & Mid(sWHEEL2, k, 1)
Else
sRESULT = sRESULT & Addpass(c,sPASSWORD)
End If
sWHEEL1 = LeftShift(sWHEEL1): sWHEEL2 = RightShift(sWHEEL2)
Next
Encrypt_PRO = sRESULT
End Function
Function Decrypt_PRO(sINPUT , sPASSWORD )
Dim sWHEEL1, sWHEEL2
Dim k, i, c
Dim sRESULT
sWHEEL1 = sDefaultWHEEL1: sWHEEL2 = sDefaultWHEEL2
ScrambleWheels sWHEEL1, sWHEEL2, sPASSWORD
sRESULT = ""
For i = 1 To Len(sINPUT)
c = Mid(sINPUT, i, 1)
k = InStr(1, sWHEEL2, c, vbBinaryCompare)
If k > 0 Then
sRESULT = sRESULT & Mid(sWHEEL1, k, 1)
Else
sRESULT = sRESULT & Addpass(c,sPASSWORD)
End If
sWHEEL1 = LeftShift(sWHEEL1): sWHEEL2 = RightShift(sWHEEL2)
Next
Decrypt_PRO = sRESULT
End Function
Function LeftShift(s )
If Len(s) > 0 Then LeftShift = Mid(s, 2, Len(s) - 1) & Mid(s, 1, 1)
End Function
Function RightShift(s )
If Len(s) > 0 Then RightShift = Mid(s, Len(s), 1) & Mid(s, 1, Len(s) - 1)
End Function
Sub ScrambleWheels(ByRef sW1 , ByRef sW2 , sPASSWORD )
Dim i ,k
For i = 1 To Len(sPASSWORD)
For k = 1 To Asc(Mid(sPASSWORD, i, 1)) * i
sW1 = LeftShift(sW1): sW2 = RightShift(sW2)
Next
Next
End Sub
Function Addpass(tStr,tPass)
Select Case tStr
Case Chr(13)
Addpass = tStr
Case Chr(10)
Addpass = tStr
Case Chr(13)+Chr(10)
Addpass = tStr
Case Chr(9)
Addpass = tStr
Case Else
Addpass = Chr((Asc(tPass) Xor Len(tPass)) Xor Asc(tStr))
End Select
End Function
Function ReadFile(FileName)
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath(FileName), ForReading, True)
ReadFile = f.ReadAll
f.Close
End Function
Sub WriteFile(FileName,Str)
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath(FileName), ForWriting, True)
f.Write Str
f.Close
End Sub
%>
--------------------------加密代码的使用方法-----------------------
从文件index_buk.Htm中读加密后写到index.htm文件中然后解密并显示
也是所谓的Asp代码与HTML代码分离。
Index_buk.htm代码为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
<link href="css/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
color: #990000;
font-weight: bold;
}
-->
</style>
<body>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="cccccc">
<tr align="center" bgcolor="#efefef">
<td colspan="2"><span class="style1">系统发生错误!</span></td>
</tr>
<tr bgcolor="ffffff">
<td colspan="2">{$MsgCon$}</td>
</tr>
<tr bgcolor="ffffff">
<td colspan="2" align="center"><< <a href="javascript:history.go(-1);">返回重新操作</a> >></td>
</tr>
</table>
<p align="center"> </p>
</body>
</html>
——————————————ASP代码调用----------------------
<!--#include file="Function.asp" -->
<%
Rem =================================================================
Rem = 函数文件:Function.asp
Rem = 测试文件:TestEncrypt.asp,Encryptpass.asp
Rem = 说明:Encrypt_PRO加密函数,Decrypt_PRO解密函数
Rem = 代码算法需要重写,可能知道的人多了就不太安全了。
Rem =================================================================
Str = ReadFile("index_buk.Htm")
Pass = "cexo"
Encrypt_Str = Encrypt_PRO(Str,Pass)
Decrypt_Str = Decrypt_PRO(Encrypt_Str,Pass)
Response.Write Encrypt_Str
WriteFile "Index.htm",Encrypt_Str
Response.Write Decrypt_Str
Str2 = ReadFile("index.Htm")
Decrypt_Str = Decrypt_PRO(Str2,Pass)
Str3 = "<li>1111111111111111111111111111</li><br>
<li>1111111111111111111111111111</li><br>
<li>22222222222222222222222222222</li><br>
<li>33333333333333333333333333</li><br>"
Msg = Replace(Decrypt_Str,"{$MsgCon$}",Str3)
Response.Write Msg
%>
--------------------------加密数据的使用方法-----------------------
<%
Rem =================================================================
Rem = 函数文件:Function.asp
Rem = 测试文件:TestEncrypt.asp,Encryptpass.asp
Rem = 说明:Encrypt_PRO加密函数,Decrypt_PRO解密函数
Rem = 适用:对数据的加密,或对代码的加密,可加密中文/英文等。
Rem =================================================================
%>
<!--#include file="Function.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>加密解密实例</title>
</head>
<body>
<%
Pass = Request("txtpass")
If Pass = Null Then Pass = ""
%>
<form name="form1" method="post" action="TestEncrypt.asp">
请输入要加密的文本:<br>
<textarea name="txt1" cols="80" rows="10"><%=server.HTMLEncode(Decrypt_PRO(Request("txt2"),Pass))%></textarea>
<br>
求得解密文本为: 密码为:
<input name="txtpass" type="text" id="txtpass" value="<%=Pass%>">
<br>
<textarea name="txt2" cols="80" rows="10"><%=Encrypt_PRO(Request("txt1"),Pass)%></textarea>
<br><input type="submit" name="Submit" value="加密">
<input type="submit" name="Submit2" value="解密">
</form>
</body>
</html>
下面是ASP加密
Function.asp
<%
Rem =================================================================
Rem = 函数文件:Function.asp
Rem = 测试文件:TestEncrypt.asp,Encryptpass.asp
Rem = 说明:Encrypt_PRO加密函数,Decrypt_PRO解密函数
Rem = 代码算法需要重写,可能知道的人多了就不太安全了。
=================================================================
Public Const sDefaultWHEEL1 = "ABCDEFGHIJKLMNOPQRSTVUWXYZ_1234567890qwertyuiopasd!@#$%^&*(),. ~`-=\?/’""fghjklzxcvbnm<>;"
Public Const sDefaultWHEEL2 = "IWEHJKTLZVOPFG_1234567890qwerBNMQRYUASDXCfghjklzxc ~`-=\?/’""!@#$%^&*(),.vbnm<>;tyuiopasd"
Function Encrypt_PRO(sINPUT , sPASSWORD )
Dim sWHEEL1, sWHEEL2
Dim k, c, i
Dim sRESULT
sWHEEL1 = sDefaultWHEEL1: sWHEEL2 = sDefaultWHEEL2
ScrambleWheels sWHEEL1, sWHEEL2, sPASSWORD
sRESULT = ""
For i = 1 To Len(sINPUT)
c = Mid(sINPUT, i, 1)
k = InStr(1, sWHEEL1, c)
If k > 0 Then
sRESULT = sRESULT & Mid(sWHEEL2, k, 1)
Else
sRESULT = sRESULT & Addpass(c,sPASSWORD)
End If
sWHEEL1 = LeftShift(sWHEEL1): sWHEEL2 = RightShift(sWHEEL2)
Next
Encrypt_PRO = sRESULT
End Function
Function Decrypt_PRO(sINPUT , sPASSWORD )
Dim sWHEEL1, sWHEEL2
Dim k, i, c
Dim sRESULT
sWHEEL1 = sDefaultWHEEL1: sWHEEL2 = sDefaultWHEEL2
ScrambleWheels sWHEEL1, sWHEEL2, sPASSWORD
sRESULT = ""
For i = 1 To Len(sINPUT)
c = Mid(sINPUT, i, 1)
k = InStr(1, sWHEEL2, c, vbBinaryCompare)
If k > 0 Then
sRESULT = sRESULT & Mid(sWHEEL1, k, 1)
Else
sRESULT = sRESULT & Addpass(c,sPASSWORD)
End If
sWHEEL1 = LeftShift(sWHEEL1): sWHEEL2 = RightShift(sWHEEL2)
Next
Decrypt_PRO = sRESULT
End Function
Function LeftShift(s )
If Len(s) > 0 Then LeftShift = Mid(s, 2, Len(s) - 1) & Mid(s, 1, 1)
End Function
Function RightShift(s )
If Len(s) > 0 Then RightShift = Mid(s, Len(s), 1) & Mid(s, 1, Len(s) - 1)
End Function
Sub ScrambleWheels(ByRef sW1 , ByRef sW2 , sPASSWORD )
Dim i ,k
For i = 1 To Len(sPASSWORD)
For k = 1 To Asc(Mid(sPASSWORD, i, 1)) * i
sW1 = LeftShift(sW1): sW2 = RightShift(sW2)
Next
Next
End Sub
Function Addpass(tStr,tPass)
Select Case tStr
Case Chr(13)
Addpass = tStr
Case Chr(10)
Addpass = tStr
Case Chr(13)+Chr(10)
Addpass = tStr
Case Chr(9)
Addpass = tStr
Case Else
Addpass = Chr((Asc(tPass) Xor Len(tPass)) Xor Asc(tStr))
End Select
End Function
Function ReadFile(FileName)
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath(FileName), ForReading, True)
ReadFile = f.ReadAll
f.Close
End Function
Sub WriteFile(FileName,Str)
Dim fso, f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath(FileName), ForWriting, True)
f.Write Str
f.Close
End Sub
%>
--------------------------加密代码的使用方法-----------------------
从文件index_buk.Htm中读加密后写到index.htm文件中然后解密并显示
也是所谓的Asp代码与HTML代码分离。
Index_buk.htm代码为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
<link href="css/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
color: #990000;
font-weight: bold;
}
-->
</style>
<body>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="cccccc">
<tr align="center" bgcolor="#efefef">
<td colspan="2"><span class="style1">系统发生错误!</span></td>
</tr>
<tr bgcolor="ffffff">
<td colspan="2">{$MsgCon$}</td>
</tr>
<tr bgcolor="ffffff">
<td colspan="2" align="center"><< <a href="javascript:history.go(-1);">返回重新操作</a> >></td>
</tr>
</table>
<p align="center"> </p>
</body>
</html>
——————————————ASP代码调用----------------------
<!--#include file="Function.asp" -->
<%
Rem =================================================================
Rem = 函数文件:Function.asp
Rem = 测试文件:TestEncrypt.asp,Encryptpass.asp
Rem = 说明:Encrypt_PRO加密函数,Decrypt_PRO解密函数
Rem = 代码算法需要重写,可能知道的人多了就不太安全了。
Rem =================================================================
Str = ReadFile("index_buk.Htm")
Pass = "cexo"
Encrypt_Str = Encrypt_PRO(Str,Pass)
Decrypt_Str = Decrypt_PRO(Encrypt_Str,Pass)
Response.Write Encrypt_Str
WriteFile "Index.htm",Encrypt_Str
Response.Write Decrypt_Str
Str2 = ReadFile("index.Htm")
Decrypt_Str = Decrypt_PRO(Str2,Pass)
Str3 = "<li>1111111111111111111111111111</li><br>
<li>1111111111111111111111111111</li><br>
<li>22222222222222222222222222222</li><br>
<li>33333333333333333333333333</li><br>"
Msg = Replace(Decrypt_Str,"{$MsgCon$}",Str3)
Response.Write Msg
%>
--------------------------加密数据的使用方法-----------------------
<%
Rem =================================================================
Rem = 函数文件:Function.asp
Rem = 测试文件:TestEncrypt.asp,Encryptpass.asp
Rem = 说明:Encrypt_PRO加密函数,Decrypt_PRO解密函数
Rem = 适用:对数据的加密,或对代码的加密,可加密中文/英文等。
Rem =================================================================
%>
<!--#include file="Function.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>加密解密实例</title>
</head>
<body>
<%
Pass = Request("txtpass")
If Pass = Null Then Pass = ""
%>
<form name="form1" method="post" action="TestEncrypt.asp">
请输入要加密的文本:<br>
<textarea name="txt1" cols="80" rows="10"><%=server.HTMLEncode(Decrypt_PRO(Request("txt2"),Pass))%></textarea>
<br>
求得解密文本为: 密码为:
<input name="txtpass" type="text" id="txtpass" value="<%=Pass%>">
<br>
<textarea name="txt2" cols="80" rows="10"><%=Encrypt_PRO(Request("txt1"),Pass)%></textarea>
<br><input type="submit" name="Submit" value="加密">
<input type="submit" name="Submit2" value="解密">
</form>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
2014-01-13
展开全部
有这样的作业??思考题吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询