<% dim password,depassword
function Encode(password) coun=len(password) '得到密码的长度,付给coun changse_psd="0" '定义变量changse_psd(字符型),初值是0 for i=0 to coun-1 arr=trim(right(left(password,i+1),1)) '定义arr得到密码的每个字符(和for有关系) brr=brr&(hex(asc(arr)*2))'密码的每个字符转为asc码,乘2,又换为16进制的字符串,付给brr if i<coun-1 then '不是最后一个字符时 brr=brr&"00" '在brr后面加 00 else '最后一个时加一个 0 brr=brr&"0" end if next Encode=changse_psd&brr end function
function Decode(depassword) brr=mid(depassword,2,len(depassword)-2) brr=replace(brr,"00","") for i=1 to len(brr) step 2 decode=decode & chr(cint("&H" & mid(brr,i,2)) /2) next end function
if request.Form("Submit")="Encode" then password=request.form("password") depassword=Encode(password) else depassword=request.form("depassword") password=Decode(depassword) end if %>
<form method="post"> 原来字符:<input type="text" value="<%=password%>" name="password" size="40"><br> 加密字符:<input type="text" value="<%=depassword%>" name="depassword" size="40"> <input type="submit" value="Encode" name="Submit"><input type="submit" value="Decode" name="Submit"> </form>