验证码的程序及原理

2016-01-29 17:08 8 1 收藏

验证码的程序及原理,验证码的程序及原理

【 tulaoshi.com - ASP 】

一共4个页面:form.asp; chk.asp; num.asp; count.asp
得到一个随即数字。加密!
解密后成成XBM图片
利用session 判断

form.asp


<%
'### To encrypt/decrypt include this code in your page
'### strMyEncryptedString = EncryptString(strString)
'### strMyDecryptedString = DeCryptString(strMyEncryptedString)
'### You are free to use this code as long as credits remain in place
'### also if you improve this code let me know.

Private Function EncryptString(strString)
'####################################################################
'### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@yahoo.com ###
'### Arguments: strString <--- String you wish to encrypt ###
'### Output: Encrypted HEX string ###
'####################################################################

Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
Randomize Timer

intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize

If IsNull(strString) = False Then
strRAW = strString
intStringLen = Len(strRAW)

For i = 0 to intStringLen - 1
strTemp = Left(strRAW, 1)
strRAW = Right(strRAW, Len(strRAW) - 1)
CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
Next

EncryptString = CharHexSet & "" & Hex(intOffSet + intKey) & "" & Hex(intOffSet)
Else
EncryptString = ""
End If
End Function



Private Function DeCryptString(strCryptString)
'####################################################################
'### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@yahoo.com ###
'### Arguments: Encrypted HEX stringt ###
'### Output: Decrypted ASCII string ###
'####################################################################
'### Note this function uses HexConv() and get_hxno() functions ###
'### so make sure they are not removed ###
'####################################################################

Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData


strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, ""))
intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,""))
intKey = HexConv(Left(strRawKey, InStr(strRawKey, "") - 1)) - HexConv(intOffSet)
strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))


arHexCharSet = Split(strHexCrypData, Hex(intKey))

For i=0 to UBound(arHexCharSet)
strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
Next

DeCryptString = strRAW
End Function


Private Function HexConv(hexVar)
Dim hxx, hxx_var, multiply
IF hexVar <"" THEN
hexVar = UCASE(hexVar)
hexVar = StrReverse(hexVar)
DIM hx()
REDIM hx(LEN(hexVar))
hxx = 0
hxx_var = 0
FOR hxx = 1 TO LEN(hexVar)
IF multiply = "" THEN multiply = 1
hx(hxx) = mid(hexVar,hxx,1)
hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
multiply = (multiply * 16)
NEXT
hexVar = hxx_var
HexConv = hexVar
END IF
End Function

Private Function get_hxno(ghx)
If ghx = "A" Then
ghx = 10
ElseIf ghx = "B" Then
ghx = 11
ElseIf ghx = "C" Then
ghx = 12
ElseIf ghx = "D" Then
ghx = 13
ElseIf ghx = "E" Then
ghx = 14
ElseIf ghx = "F" Then
ghx = 15
End If
get_hxno = ghx
End Function


%


<%
randomize
num = int(7999*rnd+2000) '计数器的值
num2 = EncryptString(num)
session("pwdt")=num
%
<form action="chk.asp" method=post
请输入验证码: <input type="text" name="pwds"
<img src="http://img.jcwcn.com/attachment/portal"<input type=submit value=提交
</form


chk.asp
<%
if trim(request.form("pwds"))<trim(session("pwdt")) then
%
输入错误: 应该为:<%=session("pwdt")%,可你输入的是:<%=reque

来源:http://www.tulaoshi.com/n/20160129/1500446.html

延伸阅读
标签: Web开发
%@page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*"% %!   //create by smallnest   //email: smallnest@gmail.com   //website:www.kuaff.com   //生成随机颜色   Color getRandColor(Random random, int fc, int bc) {  &nb...
标签: ASP
  Call Com_CreatValidCode("ValidCode") Sub Com_CreatValidCode(pSN) 'Author: Layen 'QQ: 84815733 'E-mail: support@ssaw.net ' 禁止缓存 Response.Expires = -9999 Response.AddHeader "Pragma","no-cache" Response.AddHeader "cache-ctrol","no-cache" Response.ContentType = "Image/BMP" Randomize Dim i, ii, iii Const...
标签: Web开发
image.jsp 代码如下: %@ page language="java" import="java.util.*" pageEncoding="GBK"% % String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; % %@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util...
标签: 生活常识
12306图片验证码如何使用   12306图片验证码如何使用 12306官网为了减少抢票软件的使用,防止黄牛党,推出了图片验证码的方式完成登陆或者下单,有的人一开始对这个图片验证不熟悉,进行图片验证时老是出错,引得不少人吐槽。 如何通过12306图片验证码完成登陆? 进入12306官网之后,来到车票预订页面,再点击顶部...
标签: Web开发
思路: 图片验证码的实现主要的技术点是如何生成一个图片。生成图片可以使用java.awt包下的类来实现。我们先写一个简单的生成图片的程序HelloImage.java。以下是代码部分。 package com.vogoal.test; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOExcept...