'*******************************************************************
'取得ip地址
'*******************************************************************
function userip()
dim getclientip
'如果客户端用了代理服务器,则应该用servervariables("http_x_forwarded_for")方法
getclientip = request.servervariables("http_x_forwarded_for")
if getclientip = "" or isnull(getclientip) or isempty(getclientip) then
'如果客户端没用代理,应该用request.servervariables("remote_addr")方法
getclientip = request.servervariables("remote_addr")
end if
userip = getclientip
end function
'*******************************************************************
'转换ip地址
'*******************************************************************
function cip(sip)
tip = cstr(sip)
sip1 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip2 = left(tip, cint(instr(tip, ".") -1))
tip = mid(tip, cint(instr(tip, ".") + 1))
sip3 = left(tip, cint(instr(tip, ".") -1))
sip4 = mid(tip, cint(instr(tip, ".") + 1))
cip = cint(sip1) * 256 * 256 * 256 + cint(sip2) * 256 * 256 + cint(sip3) * 256 + cint(sip4)
end function
'*******************************************************************
' 弹出对话框
'*******************************************************************
sub alert(message)
message = replace(message, "'", "'")
response.write ("<script>alert('" & message & "')</script>")
end sub
'*******************************************************************
' 返回上一页,一般用在判断信息提交是否完全之后
'*******************************************************************
sub goback()
response.write ("<script>history.go(-1)</script>")
end sub
'*******************************************************************
' 重定向另外的连接
'*******************************************************************
sub go(url)
response.write ("<script>location.href('" & url & "')</script>")
end sub
'*******************************************************************
' 我比较喜欢将以上三个结合起来使用
'*******************************************************************
function alert(message, gourl)
message = replace(message, "'", "'")
if gourl = "-1" then
response.write ("<script language=javascript>alert('" & message & "');history.go(-1)</script>")
else
response.write ("<script language=javascript>alert('" & message & "');location='" & gourl &"'</script>")
end if
response.end()
end function
'*******************************************************************
' 指定秒数重定向另外的连接
'*******************************************************************
sub gopage(url, s)
s = s * 1000
response.write "<script language=javascript>"
response.write "window.settimeout("&chr(34)&"window.navigate('"&url&"')"&chr(34)&","&s&")"
response.write "</script>"
end sub
'*******************************************************************
' 判断数字是否整形
'*******************************************************************
function isinteger(para)
on error resume next
dim str
dim l, i
if isnull(para) then
isinteger = false
exit function
end if
str = cstr(para)
if trim(str) = "" then
isinteger = false
exit function
end if
l = len(str)
for i = 1 to l
if mid(str, i, 1)>"9" or mid(str, i, 1)<"0" then
isinteger = false
exit function
end if
next
isinteger = true
if err.number<>0 then err.clear
end function
'*******************************************************************
' 获得文件扩展名
'*******************************************************************
function getextend(filename)
dim tmp
if filename<>"" then
tmp = mid(filename, instrrev(filename, ".") + 1, len(filename) - instrrev(filename, "."))
tmp = lcase(tmp)
if instr(1, tmp, "asp")>0 or instr(1, tmp, "php")>0 or instr(1, tmp, "php3")>0 or instr(1, tmp, "aspx")>0 then
getextend = "txt"
else
getextend = tmp
end if
else
getextend = ""
end if
end function
' *----------------------------------------------------------------------------
' * 函数:checkin
' * 描述:检测参数是否有sql危险字符
' * 参数:str要检测的数据
' * 返回:false:安全 true:不安全
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function checkin(str)
if instr(1, str, chr(39))>0 or instr(1, str, chr(34))>0 or instr(1, str, chr(59))>0 then
checkin = true
else
checkin = false
end if
end function
' *----------------------------------------------------------------------------
' * 函数:htmlencode
' * 描述:过滤html代码
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function htmlencode(fstring)
if not isnull(fstring) then
fstring = replace(fstring, ">", ">")
fstring = replace(fstring, "<", "<")
fstring = replace(fstring, chr(32), " ")
fstring = replace(fstring, chr(9), " ")
fstring = replace(fstring, chr(34), """)
fstring = replace(fstring, chr(39), "'")
fstring = replace(fstring, chr(13), "")
fstring = replace(fstring, chr(10) & chr(10), "</p><p> ")
fstring = replace(fstring, chr(10), "<br> ")
htmlencode = fstring
end if
end function
' *----------------------------------------------------------------------------
' * 函数:htmlcode
' * 描述:过滤表单字符
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function htmlcode(fstring)
if not isnull(fstring) then
fstring = replace(fstring, chr(13), "")
fstring = replace(fstring, chr(10) & chr(10), "</p><p>")
fstring = replace(fstring, chr(34), "")
fstring = replace(fstring, chr(10), "<br>")
htmlcode = fstring
end if
end function
%>
<%
1.检查是否有效邮件地址
function checkemail(stremail)
dim re
set re = new regexp
re.pattern = "^[w-.]{1,}@([da-za-z-]{1,}.){1,}[da-za-z-]{2,3}$"
re.ignorecase = true
checkemail = re.test(stremail)
end function
2.测试变量是否为空值,空值的含义包括:变量不存在 / 为空,对象为nothing,0,空数组,字符串为空
function isblank(byref var)
isblank = false
select case true
case isobject(var)
if var is nothing then isblank = true
case isempty(var), isnull(var)
isblank = true
case isarray(var)
if ubound(var) = 0 then isblank = true
case isnumeric(var)
if (var = 0) then isblank = true
case else
if trim(var) = "" then isblank = true
end select
end function
3.得到浏览器目前的url
function getcururl()
if request.servervariables("https") = "on" then
getcurrenturl = "https://"
else
getcurrenturl = "http://"
end if
getcururl = getcururl & request.servervariables("server_name")
if (request.servervariables("server_port") <> 80) then getcururl = getcururl & ":" & request.servervariables("server_port")
getcururl = getcururl & request.servervariables("url")
if (request.querystring <> "") then getcururl = getcururl & "?" & request.querystring
end function
4.md5加密函数
private const bits_to_a_byte = 8
private const bytes_to_a_word = 4
private const bits_to_a_word = 32
private m_lonbits(30)
private m_l2power(30)
m_lonbits(0) = clng(1)
m_lonbits(1) = clng(3)
m_lonbits(2) = clng(7)
m_lonbits(3) = clng(15)
m_lonbits(4) = clng(31)
m_lonbits(5) = clng(63)
m_lonbits(6) = clng(127)
m_lonbits(7) = clng(255)
m_lonbits(8) = clng(511)
m_lonbits(9) = clng(1023)
m_lonbits(10) = clng(2047)
m_lonbits(11) = clng(4095)
m_lonbits(12) = clng(8191)
m_lonbits(13) = clng(16383)
m_lonbits(14) = clng(32767)
m_lonbits(15) = clng(65535)
m_lonbits(16) = clng(131071)
m_lonbits(17) = clng(262143)
m_lonbits(18) = clng(524287)
m_lonbits(19) = clng(1048575)
m_lonbits(20) = clng(2097151)
m_lonbits(21) = clng(4194303)
m_lonbits(22) = clng(8388607)
m_lonbits(23) = clng(16777215)
m_lonbits(24) = clng(33554431)
m_lonbits(25) = clng(67108863)
m_lonbits(26) = clng(134217727)
m_lonbits(27) = clng(268435455)
m_lonbits(28) = clng(536870911)
m_lonbits(29) = clng(1073741823)
m_lonbits(30) = clng(2147483647)
m_l2power(0) = clng(1)
m_l2power(1) = clng(2)
m_l2power(2) = clng(4)
m_l2power(3) = clng(8)
m_l2power(4) = clng(16)
m_l2power(5) = clng(32)
m_l2power(6) = clng(64)
m_l2power(7) = clng(128)
m_l2power(8) = clng(256)
m_l2power(9) = clng(512)
m_l2power(10) = clng(1024)
m_l2power(11) = clng(2048)
m_l2power(12) = clng(4096)
m_l2power(13) = clng(8192)
m_l2power(14) = clng(16384)
m_l2power(15) = clng(32768)
m_l2power(16) = clng(65536)
m_l2power(17) = clng(131072)
m_l2power(18) = clng(262144)
m_l2power(19) = clng(524288)
m_l2power(20) = clng(1048576)
m_l2power(21) = clng(2097152)
m_l2power(22) = clng(4194304)
m_l2power(23) = clng(8388608)
m_l2power(24) = clng(16777216)
m_l2power(25) = clng(33554432)
m_l2power(26) = clng(67108864)
m_l2power(27) = clng(134217728)
m_l2power(28) = clng(268435456)
m_l2power(29) = clng(536870912)
m_l2power(30) = clng(1073741824)
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function rotateleft(lvalue, ishiftbits)
rotateleft = lshift(lvalue, ishiftbits) or rshift(lvalue, (32 - ishiftbits))
end function
private function addunsigned(lx, ly)
dim lx4
dim ly4
dim lx8
dim ly8
dim lresult
lx8 = lx and &h80000000
ly8 = ly and &h80000000
lx4 = lx and &h40000000
ly4 = ly and &h40000000
lresult = (lx and &h3fffffff) + (ly and &h3fffffff)
if lx4 and ly4 then
lresult = lresult xor &h80000000 xor lx8 xor ly8
elseif lx4 or ly4 then
if lresult and &h40000000 then
lresult = lresult xor &hc0000000 xor lx8 xor ly8
else
lresult = lresult xor &h40000000 xor lx8 xor ly8
end if
else
lresult = lresult xor lx8 xor ly8
end if
addunsigned = lresult
end function
private function f(x, y, z)
f = (x and y) or ((not x) and z)
end function
private function g(x, y, z)
g = (x and z) or (y and (not z))
end function
private function h(x, y, z)
h = (x xor y xor z)
end function
private function i(x, y, z)
i = (y xor (x or (not z)))
end function
private sub ff(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(f(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub gg(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(g(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub hh(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(h(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private sub ii(a, b, c, d, x, s, ac)
a = addunsigned(a, addunsigned(addunsigned(i(b, c, d), x), ac))
a = rotateleft(a, s)
a = addunsigned(a, b)
end sub
private function converttowordarray(smessage)
dim lmessagelength
dim lnumberofwords
dim lwordarray()
dim lbyteposition
dim lbytecount
dim lwordcount
const modulus_bits = 512
const congruent_bits = 448
lmessagelength = len(smessage)
lnumberofwords = (((lmessagelength + ((modulus_bits - congruent_bits) bits_to_a_byte)) (modulus_bits bits_to_a_byte)) + 1) * (modulus_bits bits_to_a_word)
redim lwordarray(lnumberofwords - 1)
lbyteposition = 0
lbytecount = 0
do until lbytecount >= lmessagelength
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(asc(mid(smessage, lbytecount + 1, 1)), lbyteposition)
lbytecount = lbytecount + 1
loop
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(&h80, lbyteposition)
lwordarray(lnumberofwords - 2) = lshift(lmessagelength, 3)
lwordarray(lnumberofwords - 1) = rshift(lmessagelength, 29)
converttowordarray = lwordarray
end function
private function wordtohex(lvalue)
dim lbyte
dim lcount
for lcount = 0 to 3
lbyte = rshift(lvalue, lcount * bits_to_a_byte) and m_lonbits(bits_to_a_byte - 1)
wordtohex = wordtohex & right("0" & hex(lbyte), 2)
next
end function
public function md5(smessage)
dim x
dim k
dim aa
dim bb
dim cc
dim dd
dim a
dim b
dim c
dim d
const s11 = 7
const s12 = 12
const s13 = 17
const s14 = 22
const s21 = 5
const s22 = 9
const s23 = 14
const s24 = 20
const s31 = 4
const s32 = 11
const s33 = 16
const s34 = 23
const s41 = 6
const s42 = 10
const s43 = 15
const s44 = 21
x = converttowordarray(smessage)
a = &h67452301
b = &hefcdab89
c = &h98badcfe
d = &h10325476
for k = 0 to ubound(x) step 16
aa = a
bb = b
cc = c
dd = d
ff a, b, c, d, x(k + 0), s11, &hd76aa478
ff d, a, b, c, x(k + 1), s12, &he8c7b756
ff c, d, a, b, x(k + 2), s13, &h242070db
ff b, c, d, a, x(k + 3), s14, &hc1bdceee
ff a, b, c, d, x(k + 4), s11, &hf57c0faf
ff d, a, b, c, x(k + 5), s12, &h4787c62a
ff c, d, a, b, x(k + 6), s13, &ha8304613
ff b, c, d, a, x(k + 7), s14, &hfd469501
ff a, b, c, d, x(k + 8), s11, &h698098d8
ff d, a, b, c, x(k + 9), s12, &h8b44f7af
ff c, d, a, b, x(k + 10), s13, &hffff5bb1
ff b, c, d, a, x(k + 11), s14, &h895cd7be
ff a, b, c, d, x(k + 12), s11, &h6b901122
ff d, a, b, c, x(k + 13), s12, &hfd987193
ff c, d, a, b, x(k + 14), s13, &ha679438e
ff b, c, d, a, x(k + 15), s14, &h49b40821
gg a, b, c, d, x(k + 1), s21, &hf61e2562
gg d, a, b, c, x(k + 6), s22, &hc040b340
gg c, d, a, b, x(k + 11), s23, &h265e5a51
gg b, c, d, a, x(k + 0), s24, &he9b6c7aa
gg a, b, c, d, x(k + 5), s21, &hd62f105d
gg d, a, b, c, x(k + 10), s22, &h2441453
gg c, d, a, b, x(k + 15), s23, &hd8a1e681
gg b, c, d, a, x(k + 4), s24, &he7d3fbc8
gg a, b, c, d, x(k + 9), s21, &h21e1cde6
gg d, a, b, c, x(k + 14), s22, &hc33707d6
gg c, d, a, b, x(k + 3), s23, &hf4d50d87
gg b, c, d, a, x(k + 8), s24, &h455a14ed
gg a, b, c, d, x(k + 13), s21, &ha9e3e905
gg d, a, b, c, x(k + 2), s22, &hfcefa3f8
gg c, d, a, b, x(k + 7), s23, &h676f02d9
gg b, c, d, a, x(k + 12), s24, &h8d2a4c8a
hh a, b, c, d, x(k + 5), s31, &hfffa3942
hh d, a, b, c, x(k + 8), s32, &h8771f681
hh c, d, a, b, x(k + 11), s33, &h6d9d6122
hh b, c, d, a, x(k + 14), s34, &hfde5380c
hh a, b, c, d, x(k + 1), s31, &ha4beea44
hh d, a, b, c, x(k + 4), s32, &h4bdecfa9
hh c, d, a, b, x(k + 7), s33, &hf6bb4b60
hh b, c, d, a, x(k + 10), s34, &hbebfbc70
hh a, b, c, d, x(k + 13), s31, &h289b7ec6
hh d, a, b, c, x(k + 0), s32, &heaa127fa
hh c, d, a, b, x(k + 3), s33, &hd4ef3085
hh b, c, d, a, x(k + 6), s34, &h4881d05
hh a, b, c, d, x(k + 9), s31, &hd9d4d039
hh d, a, b, c, x(k + 12), s32, &he6db99e5
hh c, d, a, b, x(k + 15), s33, &h1fa27cf8
hh b, c, d, a, x(k + 2), s34, &hc4ac5665
ii a, b, c, d, x(k + 0), s41, &hf4292244
ii d, a, b, c, x(k + 7), s42, &h432aff97
ii c, d, a, b, x(k + 14), s43, &hab9423a7
ii b, c, d, a, x(k + 5), s44, &hfc93a039
ii a, b, c, d, x(k + 12), s41, &h655b59c3
ii d, a, b, c, x(k + 3), s42, &h8f0ccc92
ii c, d, a, b, x(k + 10), s43, &hffeff47d
ii b, c, d, a, x(k + 1), s44, &h85845dd1
ii a, b, c, d, x(k + 8), s41, &h6fa87e4f
ii d, a, b, c, x(k + 15), s42, &hfe2ce6e0
ii c, d, a, b, x(k + 6), s43, &ha3014314
ii b, c, d, a, x(k + 13), s44, &h4e0811a1
ii a, b, c, d, x(k + 4), s41, &hf7537e82
ii d, a, b, c, x(k + 11), s42, &hbd3af235
ii c, d, a, b, x(k + 2), s43, &h2ad7d2bb
ii b, c, d, a, x(k + 9), s44, &heb86d391
a = addunsigned(a, aa)
b = addunsigned(b, bb)
c = addunsigned(c, cc)
d = addunsigned(d, dd)
next
md5 = lcase(wordtohex(a) & wordtohex(b) & wordtohex(c) & wordtohex(d))
end function
5.sha256 加密,256位的加密哦!安全性更高!
private m_lonbits(30)
private m_l2power(30)
private k(63)
private const bits_to_a_byte = 8
private const bytes_to_a_word = 4
private const bits_to_a_word = 32
m_lonbits(0) = clng(1)
m_lonbits(1) = clng(3)
m_lonbits(2) = clng(7)
m_lonbits(3) = clng(15)
m_lonbits(4) = clng(31)
m_lonbits(5) = clng(63)
m_lonbits(6) = clng(127)
m_lonbits(7) = clng(255)
m_lonbits(8) = clng(511)
m_lonbits(9) = clng(1023)
m_lonbits(10) = clng(2047)
m_lonbits(11) = clng(4095)
m_lonbits(12) = clng(8191)
m_lonbits(13) = clng(16383)
m_lonbits(14) = clng(32767)
m_lonbits(15) = clng(65535)
m_lonbits(16) = clng(131071)
m_lonbits(17) = clng(262143)
m_lonbits(18) = clng(524287)
m_lonbits(19) = clng(1048575)
m_lonbits(20) = clng(2097151)
m_lonbits(21) = clng(4194303)
m_lonbits(22) = clng(8388607)
m_lonbits(23) = clng(16777215)
m_lonbits(24) = clng(33554431)
m_lonbits(25) = clng(67108863)
m_lonbits(26) = clng(134217727)
m_lonbits(27) = clng(268435455)
m_lonbits(28) = clng(536870911)
m_lonbits(29) = clng(1073741823)
m_lonbits(30) = clng(2147483647)
m_l2power(0) = clng(1)
m_l2power(1) = clng(2)
m_l2power(2) = clng(4)
m_l2power(3) = clng(8)
m_l2power(4) = clng(16)
m_l2power(5) = clng(32)
m_l2power(6) = clng(64)
m_l2power(7) = clng(128)
m_l2power(8) = clng(256)
m_l2power(9) = clng(512)
m_l2power(10) = clng(1024)
m_l2power(11) = clng(2048)
m_l2power(12) = clng(4096)
m_l2power(13) = clng(8192)
m_l2power(14) = clng(16384)
m_l2power(15) = clng(32768)
m_l2power(16) = clng(65536)
m_l2power(17) = clng(131072)
m_l2power(18) = clng(262144)
m_l2power(19) = clng(524288)
m_l2power(20) = clng(1048576)
m_l2power(21) = clng(2097152)
m_l2power(22) = clng(4194304)
m_l2power(23) = clng(8388608)
m_l2power(24) = clng(16777216)
m_l2power(25) = clng(33554432)
m_l2power(26) = clng(67108864)
m_l2power(27) = clng(134217728)
m_l2power(28) = clng(268435456)
m_l2power(29) = clng(536870912)
m_l2power(30) = clng(1073741824)
k(0) = &h428a2f98
k(1) = &h71374491
k(2) = &hb5c0fbcf
k(3) = &he9b5dba5
k(4) = &h3956c25b
k(5) = &h59f111f1
k(6) = &h923f82a4
k(7) = &hab1c5ed5
k(8) = &hd807aa98
k(9) = &h12835b01
k(10) = &h243185be
k(11) = &h550c7dc3
k(12) = &h72be5d74
k(13) = &h80deb1fe
k(14) = &h9bdc06a7
k(15) = &hc19bf174
k(16) = &he49b69c1
k(17) = &hefbe4786
k(18) = &hfc19dc6
k(19) = &h240ca1cc
k(20) = &h2de92c6f
k(21) = &h4a7484aa
k(22) = &h5cb0a9dc
k(23) = &h76f988da
k(24) = &h983e5152
k(25) = &ha831c66d
k(26) = &hb00327c8
k(27) = &hbf597fc7
k(28) = &hc6e00bf3
k(29) = &hd5a79147
k(30) = &h6ca6351
k(31) = &h14292967
k(32) = &h27b70a85
k(33) = &h2e1b2138
k(34) = &h4d2c6dfc
k(35) = &h53380d13
k(36) = &h650a7354
k(37) = &h766a0abb
k(38) = &h81c2c92e
k(39) = &h92722c85
k(40) = &ha2bfe8a1
k(41) = &ha81a664b
k(42) = &hc24b8b70
k(43) = &hc76c51a3
k(44) = &hd192e819
k(45) = &hd6990624
k(46) = &hf40e3585
k(47) = &h106aa070
k(48) = &h19a4c116
k(49) = &h1e376c08
k(50) = &h2748774c
k(51) = &h34b0bcb5
k(52) = &h391c0cb3
k(53) = &h4ed8aa4a
k(54) = &h5b9cca4f
k(55) = &h682e6ff3
k(56) = &h748f82ee
k(57) = &h78a5636f
k(58) = &h84c87814
k(59) = &h8cc70208
k(60) = &h90befffa
k(61) = &ha4506ceb
k(62) = &hbef9a3f7
k(63) = &hc67178f2
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
rshift = (rshift or (&h40000000 m_l2power(ishiftbits - 1)))
end if
end function
private function addunsigned(lx, ly)
dim lx4
dim ly4
dim lx8
dim ly8
dim lresult
lx8 = lx and &h80000000
ly8 = ly and &h80000000
lx4 = lx and &h40000000
ly4 = ly and &h40000000
lresult = (lx and &h3fffffff) + (ly and &h3fffffff)
if lx4 and ly4 then
lresult = lresult xor &h80000000 xor lx8 xor ly8
elseif lx4 or ly4 then
if lresult and &h40000000 then
lresult = lresult xor &hc0000000 xor lx8 xor ly8
else
lresult = lresult xor &h40000000 xor lx8 xor ly8
end if
else
lresult = lresult xor lx8 xor ly8
end if
addunsigned = lresult
end function
private function ch(x, y, z)
ch = ((x and y) xor ((not x) and z))
end function
private function maj(x, y, z)
maj = ((x and y) xor (x and z) xor (y and z))
end function
private function s(x, n)
s = (rshift(x, (n and m_lonbits(4))) or lshift(x, (32 - (n and m_lonbits(4)))))
end function
private function r(x, n)
r = rshift(x, cint(n and m_lonbits(4)))
end function
private function sigma0(x)
sigma0 = (s(x, 2) xor s(x, 13) xor s(x, 22))
end function
private function sigma1(x)
sigma1 = (s(x, 6) xor s(x, 11) xor s(x, 25))
end function
private function gamma0(x)
gamma0 = (s(x, 7) xor s(x, 18) xor r(x, 3))
end function
private function gamma1(x)
gamma1 = (s(x, 17) xor s(x, 19) xor r(x, 10))
end function
private function converttowordarray(smessage)
dim lmessagelength
dim lnumberofwords
dim lwordarray()
dim lbyteposition
dim lbytecount
dim lwordcount
dim lbyte
const modulus_bits = 512
const congruent_bits = 448
lmessagelength = len(smessage)
lnumberofwords = (((lmessagelength + ((modulus_bits - congruent_bits) bits_to_a_byte)) (modulus_bits bits_to_a_byte)) + 1) * (modulus_bits bits_to_a_word)
redim lwordarray(lnumberofwords - 1)
lbyteposition = 0
lbytecount = 0
do until lbytecount >= lmessagelength
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (3 - (lbytecount mod bytes_to_a_word)) * bits_to_a_byte
lbyte = ascb(mid(smessage, lbytecount + 1, 1))
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(lbyte, lbyteposition)
lbytecount = lbytecount + 1
loop
lwordcount = lbytecount bytes_to_a_word
lbyteposition = (3 - (lbytecount mod bytes_to_a_word)) * bits_to_a_byte
lwordarray(lwordcount) = lwordarray(lwordcount) or lshift(&h80, lbyteposition)
lwordarray(lnumberofwords - 1) = lshift(lmessagelength, 3)
lwordarray(lnumberofwords - 2) = rshift(lmessagelength, 29)
converttowordarray = lwordarray
end function
public function sha256(smessage)
dim hash(7)
dim m
dim w(63)
dim a
dim b
dim c
dim d
dim e
dim f
dim g
dim h
dim i
dim j
dim t1
dim t2
hash(0) = &h6a09e667
hash(1) = &hbb67ae85
hash(2) = &h3c6ef372
hash(3) = &ha54ff53a
hash(4) = &h510e527f
hash(5) = &h9b05688c
hash(6) = &h1f83d9ab
hash(7) = &h5be0cd19
m = converttowordarray(smessage)
for i = 0 to ubound(m) step 16
a = hash(0)
b = hash(1)
c = hash(2)
d = hash(3)
e = hash(4)
f = hash(5)
g = hash(6)
h = hash(7)
for j = 0 to 63
if j < 16 then
w(j) = m(j + i)
else
w(j) = addunsigned(addunsigned(addunsigned(gamma1(w(j - 2)), w(j - 7)), gamma0(w(j - 15))), w(j - 16))
end if
t1 = addunsigned(addunsigned(addunsigned(addunsigned(h, sigma1(e)), ch(e, f, g)), k(j)), w(j))
t2 = addunsigned(sigma0(a), maj(a, b, c))
h = g
g = f
f = e
e = addunsigned(d, t1)
d = c
c = b
b = a
a = addunsigned(t1, t2)
next
hash(0) = addunsigned(a, hash(0))
hash(1) = addunsigned(b, hash(1))
hash(2) = addunsigned(c, hash(2))
hash(3) = addunsigned(d, hash(3))
hash(4) = addunsigned(e, hash(4))
hash(5) = addunsigned(f, hash(5))
hash(6) = addunsigned(g, hash(6))
hash(7) = addunsigned(h, hash(7))
next
sha256 = lcase(right("00000000" & hex(hash(0)), 8) & right("00000000" & hex(hash(1)), 8) & right("00000000" & hex(hash(2)), 8) & right("00000000" & hex(hash(3)), 8) & right("00000000" & hex(hash(4)), 8) & right("00000000" & hex(hash(5)), 8) & right("00000000" & hex(hash(6)), 8) & right("00000000" & hex(hash(7)), 8))
end function
6.一个if语句的加工,以后可以用类似于php或js的 if () ? ..
...代码了
function iif(condition, valueiftrue, valueiffalse)
if condition then
iif = valueiftrue
else
iif = valueiffalse
end if
end function
7.ase加密函数
private m_lonbits(30)
private m_l2power(30)
private m_bytonbits(7)
private m_byt2power(7)
private m_inco(3)
private m_fbsub(255)
private m_rbsub(255)
private m_ptab(255)
private m_ltab(255)
private m_ftable(255)
private m_rtable(255)
private m_rco(29)
private m_nk
private m_nb
private m_nr
private m_fi(23)
private m_ri(23)
private m_fkey(119)
private m_rkey(119)
m_inco(0) = &hb
m_inco(1) = &hd
m_inco(2) = &h9
m_inco(3) = &he
m_bytonbits(0) = 1
m_bytonbits(1) = 3
m_bytonbits(2) = 7
m_bytonbits(3) = 15
m_bytonbits(4) = 31
m_bytonbits(5) = 63
m_bytonbits(6) = 127
m_bytonbits(7) = 255
m_byt2power(0) = 1
m_byt2power(1) = 2
m_byt2power(2) = 4
m_byt2power(3) = 8
m_byt2power(4) = 16
m_byt2power(5) = 32
m_byt2power(6) = 64
m_byt2power(7) = 128
m_lonbits(0) = 1
m_lonbits(1) = 3
m_lonbits(2) = 7
m_lonbits(3) = 15
m_lonbits(4) = 31
m_lonbits(5) = 63
m_lonbits(6) = 127
m_lonbits(7) = 255
m_lonbits(8) = 511
m_lonbits(9) = 1023
m_lonbits(10) = 2047
m_lonbits(11) = 4095
m_lonbits(12) = 8191
m_lonbits(13) = 16383
m_lonbits(14) = 32767
m_lonbits(15) = 65535
m_lonbits(16) = 131071
m_lonbits(17) = 262143
m_lonbits(18) = 524287
m_lonbits(19) = 1048575
m_lonbits(20) = 2097151
m_lonbits(21) = 4194303
m_lonbits(22) = 8388607
m_lonbits(23) = 16777215
m_lonbits(24) = 33554431
m_lonbits(25) = 67108863
m_lonbits(26) = 134217727
m_lonbits(27) = 268435455
m_lonbits(28) = 536870911
m_lonbits(29) = 1073741823
m_lonbits(30) = 2147483647
m_l2power(0) = 1
m_l2power(1) = 2
m_l2power(2) = 4
m_l2power(3) = 8
m_l2power(4) = 16
m_l2power(5) = 32
m_l2power(6) = 64
m_l2power(7) = 128
m_l2power(8) = 256
m_l2power(9) = 512
m_l2power(10) = 1024
m_l2power(11) = 2048
m_l2power(12) = 4096
m_l2power(13) = 8192
m_l2power(14) = 16384
m_l2power(15) = 32768
m_l2power(16) = 65536
m_l2power(17) = 131072
m_l2power(18) = 262144
m_l2power(19) = 524288
m_l2power(20) = 1048576
m_l2power(21) = 2097152
m_l2power(22) = 4194304
m_l2power(23) = 8388608
m_l2power(24) = 16777216
m_l2power(25) = 33554432
m_l2power(26) = 67108864
m_l2power(27) = 134217728
m_l2power(28) = 268435456
m_l2power(29) = 536870912
m_l2power(30) = 1073741824
private function lshift(lvalue, ishiftbits)
if ishiftbits = 0 then
lshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and 1 then
lshift = &h80000000
else
lshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
if (lvalue and m_l2power(31 - ishiftbits)) then
lshift = ((lvalue and m_lonbits(31 - (ishiftbits + 1))) * m_l2power(ishiftbits)) or &h80000000
else
lshift = ((lvalue and m_lonbits(31 - ishiftbits)) * m_l2power(ishiftbits))
end if
end function
private function rshift(lvalue, ishiftbits)
if ishiftbits = 0 then
rshift = lvalue
exit function
elseif ishiftbits = 31 then
if lvalue and &h80000000 then
rshift = 1
else
rshift = 0
end if
exit function
elseif ishiftbits < 0 or ishiftbits > 31 then
err.raise 6
end if
rshift = (lvalue and &h7ffffffe) m_l2power(ishiftbits)
if (lvalue and &h80000000) then
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!