MD5算法自从1991开发出来以后广泛用于数字签名和加密解密领域。目前使用PB外的语言可以较为简单地实现了MD5加密,使用PB来实现的比较鲜见,这可能有如下两方面的原因:一,PB在位运算方面未提供直接使用的函数,要实现位运算比较麻烦;二,在PB(PB10之前的版本)中无法直接获取字符的unicode值。如果能够攻破这两个难点,在熟悉MD5算法之后应该比较容易地在PB中实现MD5加密。
PB虽然未提供位运算方面直接使用的函数,但如果了解位运算的法则,同样可以实现位运算。不论是二元运算还是一元运算,参与运算的表达式都以补码方法表示,其结果也以补码表示。通用的做法是创建一个专门用于位运算的对象,使其实现进制之间的转化、位运算、求反、求补等功能,然后在加密时调用。关于根据原码求其反码、补码的运算法则可以参考相关的计算机书籍。
在PB中虽然无法直接获取字符的unicode值(据说PB10有ASCW函数可以实现),但调用WINAPI可以实现,这个函数就是MultiByteToWideChar(注意该函数在PB环境下区分大小写),可运行于Windows95及以后的Windows操作系统。顺便提一下,目前网上大多数MD5加密算法中只取字符的ASCII,因而对于非英文语言的字符加密支持不够。
以下是MD5算法在PB中实现的源代码,读者只需将其保存到sru格式的文件中然后导入到PB库文件中生成相应对象,然后依据PB的对象调用规则便可使用。由于作者水平有限,部分代码段未提供详细注释,敬请原谅。所有代码在PB8.0.3Build9704和Windows2000 AdvancedServer Service Pack4环境下运行正确。
限于篇幅,本文不给出MD5算法的加密原理,读者可查阅MD5算法的详细资料,如范本文件http://www.ietf.org/rfc/rfc1321.txt,在实现时可参考PFC中pfc_n_cst_numerical对象提供的位运算函数及其它语言(如C/C++/Delphi/ASP/MSSQLSERVER2000)实现MD5加密的源代码。
一,nvo_numerical对象,提供位运算功能。
forward
global type nvo_numerical from nonvisualobject
end type
end forward
global type nvo_numerical from nonvisualobject autoinstantiate
end type
forward prototypes
public function string of_binary (unsignedlong aul_decimal)
public function string of_binary (long al_decimal)
public function unsignedlong of_binarytodecimalunsigned (string as_binary)
public function long of_decimal (string as_binary)
public function string of_bitwisenot (string as_bitvalue)
public function string of_bitwisefill (string as_bitvalue)
public function long of_bitwiseand (long al_value1, long al_value2)
public function long of_bitwiseor (long al_value1, long al_value2)
public function long of_bitwisexor (long al_value1, long al_value2)
end prototypes
public function string of_binary (unsignedlong aul_decimal);
/*******************************************************************
函数名称:of_binary()
参数: aul_decimal unsignedlong 数字
返回值: string 二进制字符
功能描述:将数字转为二进制字符
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
string ls_binary=''
//检查参数
If IsNull(aul_decimal) Then
SetNull(ls_binary)
Return ls_binary
End If
Do
ls_binary = string(mod(aul_decimal, 2)) + ls_binary
aul_decimal = aul_decimal /2
Loop Until aul_decimal= 0
Return ls_binary
end function
public function string of_binary (long al_decimal);
/*******************************************************************
函数名称:of_binary()
参数: al_decimal long 数字
返回值: string 二进制字符
功能描述:将数字转为二进制字符
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_remainder
string ls_return='',ls_null
ulong ll_temp
//检查参数
if isnull(al_decimal) then
setnull(ls_null)
return ls_null
end if
//处理零
if al_decimal = 0 then
return '0'
end if
//处理负数
if al_decimal< 0 then
ll_temp = abs(al_decimal)//取绝对值
//负数的二进制码为其绝对值的二进制码前加负号
return '-' + this.of_binary(ll_temp)//取绝对值的二进制码
end if
do until al_decimal= 0
li_remainder = mod(al_decimal, 2)
al_decimal = al_decimal /2
ls_return = string(li_remainder) + ls_return
loop
return ls_return
end function
public function unsignedlong of_binarytodecimalunsigned (string as_binary);/*******************************************************************
函数名称:of_binarytodecimalunsigned()
参数: as_binary string 二进制值
返回值: unsignedlong 无符号位十进制值
功能描述:二进制值转成无符号位十进制
创建人: 康剑民
创建日期:2004-05-23(第一版)
版本号: v1.0.0
*******************************************************************/
integer li_cnt
long ll_len,ll_null
long ll_decimal=0
//检查参数
If IsNull(as_binary) then
SetNull(ll_null)
Return ll_null
End If
ll_len = lenw(as_binary)
For li_cnt = 1 to ll_len
//只允许出现0或1
If (Not midw(as_binary,li_cnt,1)='1') AND (Not midw(as_binary,li_cnt,1)='0') Then
Return -1
End If
if midw(as_binary,li_cnt,1) = '1' then
ll_decimal = ll_decimal + (2 ^ (ll_len - li_cnt))
end if
Next
Return ll_decimal
end function
public function long of_decimal (string as_binary);
/*******************************************************************
函数名称:of_decimal()
参数: as_binary 二进制值
返回值: long 十进制值
功能描述:将二进制值转十进制
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_cnt
long ll_len,ll_null
char lch_char[]
long ll_decimal=0
//检查参数
if isnull(as_binary) then
setnull(ll_null)
return ll_null
end if
ll_len = lenw(as_binary)
for li_cnt = 1 to ll_len
//只允许存在0和1字符
if (not midw(as_binary,li_cnt,1)='1') and (not midw(as_binary,li_cnt,1)='0') then
return -1
end if
if midw(as_binary,li_cnt,1) = '1' then
ll_decimal = ll_decimal + (2 ^ (ll_len - li_cnt))
end if
next
return ll_decimal
end function
public function string of_bitwisenot (string as_bitvalue);
/*******************************************************************
函数名称:of_bitwisenot()
参数: as_bitvalue string 二进制值
返回值: string 反码
功能描述:求二进制反码
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_cnt, li_count
long ll_result
string ls_value, ls_result
//检查参数
if isnull(as_bitvalue) then
setnull(ls_result)
return ls_result
end if
li_cnt = lenw(as_bitvalue)
//将0变为1,1变为0
for li_count = 1 to li_cnt
if midw(as_bitvalue, li_count, 1) = '0' then
ls_result = ls_result + '1'
else
ls_result = ls_result + '0'
end if
end for
return ls_result
end function
public function string of_bitwisefill (string as_bitvalue);
/*******************************************************************
函数名称:of_bitwisefill()
参数: as_bitvalue string 二进制值
返回值: string 补码
功能描述:求二进制补码(要求前四位为符号位,1111表示负数,0000表示正数)
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_cnt, li_count,li_pos
long ll_result
string ls_value, ls_result
boolean lb_exit=false
//检查参数
if isnull(as_bitvalue) then
setnull(ls_result)
return ls_result
end if
//正数的补码为其本身
if leftw(as_bitvalue,4) = '0000' then
return as_bitvalue
else
//负数的补码为反码加1
as_bitvalue = midw(as_bitvalue,5,lenw(as_bitvalue))
//求反码
ls_result = this.of_bitwisenot(as_bitvalue)
//低位加1
li_pos = lastpos(ls_result,'0')
if li_pos = 0 then
ls_result = fill('0',li_count)
else
ls_result = leftw(ls_result,li_pos - 1) + '1' + fill('0',lenw(ls_result) - li_pos)
end if
return fill('1',4) + fill('0',ceiling(lenw(ls_result) / 4) * 4 - lenw(ls_result)) + ls_result
end if
end function
public function long of_bitwiseand (long al_value1, long al_value2);
/*******************************************************************
函数名称:of_bitwiseand()
参数: al_value1 long 值1
al_value2 long 值2
返回值: long 按位与运算后的结果
功能描述:按位与运算
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_cnt,li_len
long ll_result
string ls_bitvalue1,ls_bitvalue2,ls_return,ls_sign
//检查参数
if isnull(al_value1) or isnull(al_value2) then
setnull(ll_result)
return ll_result
end if
ls_bitvalue1 = this.of_binary(al_value1)//取值1的二进制值
ls_bitvalue2 = this.of_binary(al_value2)//取值2的二进制值
//删除符号位
if leftw(ls_bitvalue1,1) = '-' then
ls_bitvalue1 = midw(ls_bitvalue1,2,lenw(ls_bitvalue1))
end if
if leftw(ls_bitvalue2,1) = '-' then
ls_bitvalue2 = midw(ls_bitvalue2,2,lenw(ls_bitvalue2))
end if
//取参与运算的二进制值长度
li_len = max(lenw(ls_bitvalue1),lenw(ls_bitvalue2))
li_len = ceiling(li_len / 4) * 4
//补位
ls_bitvalue1 = fill('0',li_len - lenw(ls_bitvalue1)) + ls_bitvalue1
ls_bitvalue2 = fill('0',li_len - lenw(ls_bitvalue2)) + ls_bitvalue2
//加符号位
if al_value1 < 0 then
ls_bitvalue1 = fill('1',4) + ls_bitvalue1
else
ls_bitvalue1 = fill('0',4) + ls_bitvalue1
end if
if al_value2 < 0 then
ls_bitvalue2 = fill('1',4) + ls_bitvalue2
else
ls_bitvalue2 = fill('0',4) + ls_bitvalue2
end if
//取补码
ls_bitvalue1 = this.of_bitwisefill(ls_bitvalue1)//取值1的二进值补码
ls_bitvalue2 = this.of_bitwisefill(ls_bitvalue2)//取值2的二进值补码
//对应位与运算(参数运算的两元素以补码表示,运算结果也以补码表示;只有二者都为1时结果才为1否则为0)
for li_cnt = 1 to li_len + 4
if midw(ls_bitvalue1,li_cnt,1) = '1' and midw(ls_bitvalue2,li_cnt,1) = '1' then
ls_return = ls_return + '1'
else
ls_return = ls_return + '0'
end if
next
//对结果取补码
ls_return = this.of_bitwisefill(ls_return)
//取结果符号
if leftw(ls_return,4) = '1111' then
ls_sign = '-'
else
ls_sign = ''
end if
ls_return = midw(ls_return,5,lenw(ls_return))
//将结果转为十进制
ll_result = this.of_binarytodecimalunsigned (ls_return)
//结果加上符号
if ls_sign = '-' then ll_result = ll_result * (-1)
return ll_result
end function
public function long of_bitwiseor (long al_value1, long al_value2);
/*******************************************************************
函数名称:of_bitwiseor()
参数: al_value1 long 值1
al_value1 long 值2
返回值: long 按位或运算结果
功能描述:按位或运算
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_cnt,li_len
long ll_result
string ls_bitvalue1,ls_bitvalue2,ls_return,ls_sign
//检查参数
if isnull(al_value1) or isnull(al_value2) then
setnull(ll_result)
return ll_result
end if
ls_bitvalue1 = this.of_binary(al_value1)//取值1的二进制值
ls_bitvalue2 = this.of_binary(al_value2)//取值2的二进制值
//删除符号位
if leftw(ls_bitvalue1,1) = '-' then
ls_bitvalue1 = midw(ls_bitvalue1,2,lenw(ls_bitvalue1))
end if
if leftw(ls_bitvalue2,1) = '-' then
ls_bitvalue2 = midw(ls_bitvalue2,2,lenw(ls_bitvalue2))
end if
//取参与运算的二进制值长度
li_len = max(lenw(ls_bitvalue1),lenw(ls_bitvalue2))
li_len = ceiling(li_len / 4) * 4
//补位
ls_bitvalue1 = fill('0',li_len - lenw(ls_bitvalue1)) + ls_bitvalue1
ls_bitvalue2 = fill('0',li_len - lenw(ls_bitvalue2)) + ls_bitvalue2
//加符号位
if al_value1 < 0 then
ls_bitvalue1 = fill('1',4) + ls_bitvalue1
else
ls_bitvalue1 = fill('0',4) + ls_bitvalue1
end if
if al_value2 < 0 then
ls_bitvalue2 = fill('1',4) + ls_bitvalue2
else
ls_bitvalue2 = fill('0',4) + ls_bitvalue2
end if
//取补码
ls_bitvalue1 = this.of_bitwisefill(ls_bitvalue1)//取值1的补码
ls_bitvalue2 = this.of_bitwisefill(ls_bitvalue2)//取值2的补码
//对应位或运算(参数运算的两元素以补码表示,运算结果也以补码表示;只要二者中有一个为1时结果为1否则为0)
for li_cnt = 1 to li_len + 4
if midw(ls_bitvalue1,li_cnt,1) = '1' or midw(ls_bitvalue2,li_cnt,1) = '1' then
ls_return = ls_return + '1'
else
ls_return = ls_return + '0'
end if
next
//对结果取补码
ls_return = this.of_bitwisefill(ls_return)
if leftw(ls_return,4) = '1111' then
ls_sign = '-'
else
ls_sign = ''
end if
ls_return = midw(ls_return,5,lenw(ls_return))
//将结果转为十进制
ll_result = this.of_binarytodecimalunsigned (ls_return)
//加上符号位
if ls_sign = '-' then ll_result = ll_result * (-1)
return ll_result
end function
public function long of_bitwisexor (long al_value1, long al_value2);
/*******************************************************************
函数名称:of_bitwiseor()
参数: al_value1 long 值1
al_value1 long 值2
返回值: long 按位异或运算结果
功能描述:按位异或运算
创建人: 康剑民
创建日期:2004-05-23
版本号: v1.0.0
*******************************************************************/
integer li_cnt,li_len
long ll_result
string ls_bitvalue1,ls_bitvalue2,ls_return,ls_sign
//检查参数
if isnull(al_value1) or isnull(al_value2) then
setnull(ll_result)
return ll_result
end if
ls_bitvalue1 = this.of_binary(al_value1)//取值1的二进制值
ls_bitvalue2 = this.of_binary(al_value2)//取值2的二进制值
//删除符号位
if leftw(ls_bitvalue1,1) = '-' then
ls_bitvalue1 = midw(ls_bitvalue1,2,lenw(ls_bitvalue1))
end if
if leftw(ls_bitvalue2,1) = '-' then
ls_bitvalue2 = midw(ls_bitvalue2,2,lenw(ls_bitvalue2))
end if
//取参与运算的二进制值长度
li_len = max(lenw(ls_bitvalue1),lenw(ls_bitvalue2))
li_len = ceiling(li_len / 4) * 4
//补位
ls_bitvalue1 = fill('0',li_len - lenw(ls_bitvalue1)) + ls_bitvalue1
ls_bitvalue2 = fill('0',li_len - lenw(ls_bitvalue2)) + ls_bitvalue2
//加符号位
if al_value1 < 0 then
ls_bitvalue1 = fill('1',4) + ls_bitvalue1
else
ls_bitvalue1 = fill('0',4) + ls_bitvalue1
end if
if al_value2 < 0 then
ls_bitvalue2 = fill('1',4) + ls_bitvalue2
else
ls_bitvalue2 = fill('0',4) + ls_bitvalue2
end if
//取补码
ls_bitvalue1 = this.of_bitwisefill(ls_bitvalue1)//取值1的补码
ls_bitvalue2 = this.of_bitwisefill(ls_bitvalue2)//取值2的补码
//对应位异或运算(参数运算的两元素以补码表示,运算结果也以补码表示;只有二者不相同时结果为1否则为0)
for li_cnt = 1 to li_len + 4
if (midw(ls_bitvalue1,li_cnt,1) = '1' and midw(ls_bitvalue2,li_cnt,1) = '0') or &
(midw(ls_bitvalue1,li_cnt,1) = '0' and midw(ls_bitvalue2,li_cnt,1) = '1') then
ls_return = ls_return + '1'
else
ls_return = ls_return + '0'
end if
next
//对结果取补码
ls_return = this.of_bitwisefill(ls_return)
if leftw(ls_return,4) = '1111' then
ls_sign = '-'
else
ls_sign = ''
end if
ls_return = midw(ls_return,5,lenw(ls_return))
//将结果转为十进制
ll_result = this.of_binarytodecimalunsigned(ls_return)
//加符号位
if ls_sign = '-' then ll_result = ll_result * (-1)
return ll_result
end function
on nvo_numerical.create
call super::create
triggerevent( this, "constructor" )
end on
on nvo_numerical.destroy
triggerevent( this, "destructor" )
call super::destroy
end on
二, nvo_md5对象,提供字符加密功能。
forward
global type nvo_md5 from nonvisualobject
end type
end forward
global type nvo_md5 from nonvisualobject autoinstantiate
end type
type prototypes
//ansi转为unicode
function int MultiByteToWideChar(uint codepage, ulong dwflags, ref string lpmultibytestr, int cchmultibyte, ref long lpwidecharstr, int cchwidechar) library "kernel32.dll"
end prototypes
type variables
nvo_numerical inv_numerical//数字服务对象
end variables
forward prototypes
private function long of_addunsigned (readonly long al_x, readonly long al_y)
private function long of_converttowordarray (readonly string as_origmess, ref long al_word[])
public function string of_encrypt (readonly string as_origmess)
private function long of_f (readonly long al_x, readonly long al_y, readonly long al_z)
private function long of_ff (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac)
private function long of_g (readonly long al_x, readonly long al_y, readonly long al_z)
private function long of_gg (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac)
private function long of_h (readonly long al_x, readonly long al_y, readonly long al_z)
private function long of_hh (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac)
private function long of_i (readonly long al_x, readonly long al_y, readonly long al_z)
private function long of_ii (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac)
private function string of_wordtohex (readonly long al_value)
private function long of_rshift (readonly long al_oldvalue, readonly long al_shiftbits)
private function long of_rotateleft (readonly long al_oldvalue, readonly long al_shiftbits)
private function long of_monbits (readonly long al_oldvalue)
private function long of_m2power (readonly long al_oldvalue)
private function long of_lshift (readonly long al_oldvalue, readonly long al_shiftbits)
private function long of_getunicode (string as_char)
end prototypes
private function long of_addunsigned (readonly long al_x, readonly long al_y);
/*******************************************************************
函数名称:of_addunsigned()
参数: al_x long 值1
al_y long 值2
返回值: long 运算结果
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24(第一版)
版本号: v1.0.0
*******************************************************************/
return al_x + al_y
end function
private function long of_converttowordarray (readonly string as_origmess, ref long al_word[]);
/*******************************************************************
函数名称:of_converttowordarray()
参数: as_origmess string 原文本
al_word[] ref long 转换后的数组
返回值: long 是否成功(1/-1)
功能描述:将字符装入数组并进行位填充
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
long ll_lenofmess,ll_wordarraylen,ll_posofword,ll_posofmess,ll_countofword
long i,ll_temp,ll_word_list[],ll_word_unicode
string ls_return,ls_char
ll_lenofmess = lenw(as_origmess)
ll_wordarraylen = (integer((ll_lenofmess + 8) / 64) + 1) * 16
ll_countofword = 0
for i = 1 to ll_wordarraylen
ll_word_list[i] = 0
next
ll_posofmess = 0
ll_posofword = 0
ll_countofword = 0
do while ll_posofmess < ll_lenofmess
ls_char = midw(as_origmess,ll_posofmess + 1,1)
ll_countofword = integer(ll_posofmess / 4)
ll_posofword = mod(ll_posofmess,4)
if ll_countofword + 1 > 0 and ll_countofword + 1 <= upperbound(ll_word_list) then
ll_word_unicode = this.of_getunicode(ls_char)//取字符的unicode值
ll_word_list[ll_countofword + 1] = inv_numerical.of_bitwiseor(ll_word_list[ll_countofword + 1],this.of_lshift(ll_word_unicode,ll_posofword * 8))
end if
ll_posofmess ++
loop
ll_countofword = integer(ll_posofmess / 4)
ll_posofword = mod(ll_posofmess,4)
if ll_countofword + 1 > 0 and ll_countofword + 1 <= upperbound(ll_word_list) then
ll_word_list[ll_countofword + 1] = inv_numerical.of_bitwiseor(ll_word_list[ll_countofword + 1],this.of_lshift(128,ll_posofword * 8))
end if
if ll_wordarraylen - 2 + 1 > 0 and ll_wordarraylen - 2 + 1 <= upperbound(ll_word_list) then
ll_word_list[ll_wordarraylen - 2 + 1] = inv_numerical.of_bitwiseor(ll_word_list[ll_wordarraylen - 2 + 1],this.of_lshift(ll_lenofmess,3))
end if
if ll_wordarraylen - 1 + 1 > 0 and ll_wordarraylen - 1 + 1 <= upperbound(ll_word_list) then
ll_word_list[ll_wordarraylen - 1 + 1] = inv_numerical.of_bitwiseor(ll_word_list[ll_wordarraylen - 1 + 1],this.of_rshift(ll_lenofmess,29))
end if
al_word = ll_word_list
return 1
end function
public function string of_encrypt (readonly string as_origmess);
/*******************************************************************
函数名称:of_encrypt()
参数: as_origmess string 原文本
返回值: string 加密后文本
功能描述:md5加密
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
long ll_word_list[16]={7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21}
long ll_a,ll_b,ll_c,ll_d,ll_aa,ll_bb,ll_cc,ll_dd,ll_temp[]
string ls_return=''
long ll_wordarraycount,ll_wordarraylen
//初始化核心变量
ll_a = 1732584193
ll_b = -271733879
ll_c = -1732584194
ll_d = 271733878
//将字符装入数组并进行位填充
this.of_converttowordarray(as_origmess,ll_temp)
ll_wordarraycount = 0
ll_wordarraylen = (long((lenw(as_origmess) + 8) / 64) + 1) * 16
do while ll_wordarraycount < ll_wordarraylen
ll_aa = ll_a
ll_bb = ll_b
ll_cc = ll_c
ll_dd = ll_d
ll_wordarraycount = ll_wordarraycount + 1
//第一轮运算
if ll_wordarraycount + 0 > 0 and ll_wordarraycount + 0 <= upperbound(ll_temp) then
ll_a = this.of_ff(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 0],ll_word_list[1],-680876936)
end if
if ll_wordarraycount + 1 > 0 and ll_wordarraycount + 1 <= upperbound(ll_temp) then
ll_d = this.of_ff(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 1],ll_word_list[2],-389564586)
end if
if ll_wordarraycount + 2 > 0 and ll_wordarraycount + 2 <= upperbound(ll_temp) then
ll_c = this.of_ff(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 2],ll_word_list[3],606105819)
end if
if ll_wordarraycount + 3 > 0 and ll_wordarraycount + 3 <= upperbound(ll_temp) then
ll_b = this.of_ff(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 3],ll_word_list[4],-1044525330)
end if
if ll_wordarraycount + 4 > 0 and ll_wordarraycount + 4 <= upperbound(ll_temp) then
ll_a = this.of_ff(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 4],ll_word_list[1],-176418897)
end if
if ll_wordarraycount + 5 > 0 and ll_wordarraycount + 5 <= upperbound(ll_temp) then
ll_d = this.of_ff(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 5],ll_word_list[2],1200080426)
end if
if ll_wordarraycount + 6 > 0 and ll_wordarraycount + 6 <= upperbound(ll_temp) then
ll_c = this.of_ff(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 6],ll_word_list[3],-1473231341)
end if
if ll_wordarraycount + 7 > 0 and ll_wordarraycount + 7 <= upperbound(ll_temp) then
ll_b = this.of_ff(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 7],ll_word_list[4],-45705983)
end if
if ll_wordarraycount + 8 > 0 and ll_wordarraycount + 8 <= upperbound(ll_temp) then
ll_a = this.of_ff(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 8],ll_word_list[1],1770035416)
end if
if ll_wordarraycount + 9 > 0 and ll_wordarraycount + 9 <= upperbound(ll_temp) then
ll_d = this.of_ff(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 9],ll_word_list[2],-1958414417)
end if
if ll_wordarraycount + 10 > 0 and ll_wordarraycount + 10 <= upperbound(ll_temp) then
ll_c = this.of_ff(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 10],ll_word_list[3],-42063)
end if
if ll_wordarraycount + 11 > 0 and ll_wordarraycount + 11 <= upperbound(ll_temp) then
ll_b = this.of_ff(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 11],ll_word_list[4],-1990404162)
end if
if ll_wordarraycount + 12 > 0 and ll_wordarraycount + 12 <= upperbound(ll_temp) then
ll_a = this.of_ff(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 12],ll_word_list[1],1804603682)
end if
if ll_wordarraycount + 13 > 0 and ll_wordarraycount + 13 <= upperbound(ll_temp) then
ll_d = this.of_ff(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 13],ll_word_list[2],-40341101)
end if
if ll_wordarraycount + 14 > 0 and ll_wordarraycount + 14 <= upperbound(ll_temp) then
ll_c = this.of_ff(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 14],ll_word_list[3],-1502002290)
end if
if ll_wordarraycount + 15 > 0 and ll_wordarraycount + 15 <= upperbound(ll_temp) then
ll_b = this.of_ff(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 15],ll_word_list[4],1236535329)
end if
//第二轮运算
if ll_wordarraycount + 1 > 0 and ll_wordarraycount + 1 <= upperbound(ll_temp) then
ll_a = this.of_gg(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 1],ll_word_list[5],-165796510)
end if
if ll_wordarraycount + 6 > 0 and ll_wordarraycount + 6 <= upperbound(ll_temp) then
ll_d = this.of_gg(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 6],ll_word_list[6],-1069501632)
end if
if ll_wordarraycount + 11 > 0 and ll_wordarraycount + 11 <= upperbound(ll_temp) then
ll_c = this.of_gg(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 11],ll_word_list[7],643717713)
end if
if ll_wordarraycount + 0 > 0 and ll_wordarraycount + 0 <= upperbound(ll_temp) then
ll_b = this.of_gg(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 0],ll_word_list[8],-373897302)
end if
if ll_wordarraycount + 5 > 0 and ll_wordarraycount + 5 <= upperbound(ll_temp) then
ll_a = this.of_gg(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 5],ll_word_list[5],-701558691)
end if
if ll_wordarraycount + 10 > 0 and ll_wordarraycount + 10 <= upperbound(ll_temp) then
ll_d = this.of_gg(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 10],ll_word_list[6],38016083)
end if
if ll_wordarraycount + 15 > 0 and ll_wordarraycount + 15 <= upperbound(ll_temp) then
ll_c = this.of_gg(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 15],ll_word_list[7],-660478335)
end if
if ll_wordarraycount + 4 > 0 and ll_wordarraycount + 4 <= upperbound(ll_temp) then
ll_b = this.of_gg(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 4],ll_word_list[8],-405537848)
end if
if ll_wordarraycount + 9 > 0 and ll_wordarraycount + 9 <= upperbound(ll_temp) then
ll_a = this.of_gg(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 9],ll_word_list[5],568446438)
end if
if ll_wordarraycount + 14 > 0 and ll_wordarraycount + 14 <= upperbound(ll_temp) then
ll_d = this.of_gg(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 14],ll_word_list[6],-1019803690)
end if
if ll_wordarraycount + 3 > 0 and ll_wordarraycount + 3 <= upperbound(ll_temp) then
ll_c = this.of_gg(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 3],ll_word_list[7],-187363961)
end if
if ll_wordarraycount + 8 > 0 and ll_wordarraycount + 8 <= upperbound(ll_temp) then
ll_b = this.of_gg(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 8],ll_word_list[8],1163531501)
end if
if ll_wordarraycount + 13 > 0 and ll_wordarraycount + 13 <= upperbound(ll_temp) then
ll_a = this.of_gg(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 13],ll_word_list[5],-1444681467)
end if
if ll_wordarraycount + 2 > 0 and ll_wordarraycount + 2 <= upperbound(ll_temp) then
ll_d = this.of_gg(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 2],ll_word_list[6],-51403784)
end if
if ll_wordarraycount + 7 > 0 and ll_wordarraycount + 7 <= upperbound(ll_temp) then
ll_c = this.of_gg(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 7],ll_word_list[7],1735328473)
end if
if ll_wordarraycount + 12 > 0 and ll_wordarraycount + 12 <= upperbound(ll_temp) then
ll_b = this.of_gg(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 12],ll_word_list[8],-1926607734)
end if
//第三轮运算
if ll_wordarraycount + 5 > 0 and ll_wordarraycount + 5 <= upperbound(ll_temp) then
ll_a = this.of_hh(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 5],ll_word_list[9],-378558)
end if
if ll_wordarraycount + 8 > 0 and ll_wordarraycount + 8 <= upperbound(ll_temp) then
ll_d = this.of_hh(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 8],ll_word_list[10],-2022574463)
end if
if ll_wordarraycount + 11 > 0 and ll_wordarraycount + 11 <= upperbound(ll_temp) then
ll_c = this.of_hh(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 11],ll_word_list[11],1839030562)
end if
if ll_wordarraycount + 14 > 0 and ll_wordarraycount + 14 <= upperbound(ll_temp) then
ll_b = this.of_hh(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 14],ll_word_list[12],-35309556)
end if
if ll_wordarraycount + 1 > 0 and ll_wordarraycount + 1 <= upperbound(ll_temp) then
ll_a = this.of_hh(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 1],ll_word_list[9],-1530992060)
end if
if ll_wordarraycount + 4 > 0 and ll_wordarraycount + 4 <= upperbound(ll_temp) then
ll_d = this.of_hh(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 4],ll_word_list[10],1272893353)
end if
if ll_wordarraycount + 7 > 0 and ll_wordarraycount + 7 <= upperbound(ll_temp) then
ll_c = this.of_hh(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 7],ll_word_list[11],-155497632)
end if
if ll_wordarraycount + 10 > 0 and ll_wordarraycount + 10 <= upperbound(ll_temp) then
ll_b = this.of_hh(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 10],ll_word_list[12],-1094730640)
end if
if ll_wordarraycount + 13 > 0 and ll_wordarraycount + 13 <= upperbound(ll_temp) then
ll_a = this.of_hh(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 13],ll_word_list[9],681279174)
end if
if ll_wordarraycount + 0 > 0 and ll_wordarraycount + 0 <= upperbound(ll_temp) then
ll_d = this.of_hh(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 0],ll_word_list[10],-358537222)
end if
if ll_wordarraycount + 3 > 0 and ll_wordarraycount + 3 <= upperbound(ll_temp) then
ll_c = this.of_hh(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 3],ll_word_list[11],-722521979)
end if
if ll_wordarraycount + 6 > 0 and ll_wordarraycount + 6 <= upperbound(ll_temp) then
ll_b = this.of_hh(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 6],ll_word_list[12],76029189)
end if
if ll_wordarraycount + 9 > 0 and ll_wordarraycount + 9 <= upperbound(ll_temp) then
ll_a = this.of_hh(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 9],ll_word_list[9],-640364487)
end if
if ll_wordarraycount + 12 > 0 and ll_wordarraycount + 12 <= upperbound(ll_temp) then
ll_d = this.of_hh(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 12],ll_word_list[10],-421815835)
end if
if ll_wordarraycount + 15 > 0 and ll_wordarraycount + 15 <= upperbound(ll_temp) then
ll_c = this.of_hh(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 15],ll_word_list[11],530742520)
end if
if ll_wordarraycount + 2 > 0 and ll_wordarraycount + 2 <= upperbound(ll_temp) then
ll_b = this.of_hh(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 2],ll_word_list[12],-995338651)
end if
//第四轮运算
if ll_wordarraycount + 0 > 0 and ll_wordarraycount + 0 <= upperbound(ll_temp) then
ll_a = this.of_ii(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 0],ll_word_list[13],-198630844)
end if
if ll_wordarraycount + 7 > 0 and ll_wordarraycount + 7 <= upperbound(ll_temp) then
ll_d = this.of_ii(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 7],ll_word_list[14],1126891415)
end if
if ll_wordarraycount + 14 > 0 and ll_wordarraycount + 14 <= upperbound(ll_temp) then
ll_c = this.of_ii(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 14],ll_word_list[15],-1416354905)
end if
if ll_wordarraycount + 5 > 0 and ll_wordarraycount + 5 <= upperbound(ll_temp) then
ll_b = this.of_ii(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 5],ll_word_list[16],-57434055)
end if
if ll_wordarraycount + 12 > 0 and ll_wordarraycount + 12 <= upperbound(ll_temp) then
ll_a = this.of_ii(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 12],ll_word_list[13],1700485571)
end if
if ll_wordarraycount + 3 > 0 and ll_wordarraycount + 3 <= upperbound(ll_temp) then
ll_d = this.of_ii(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 3],ll_word_list[14],-1894986606)
end if
if ll_wordarraycount + 10 > 0 and ll_wordarraycount + 10 <= upperbound(ll_temp) then
ll_c = this.of_ii(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 10],ll_word_list[15],-1051523)
end if
if ll_wordarraycount + 1 > 0 and ll_wordarraycount + 1 <= upperbound(ll_temp) then
ll_b = this.of_ii(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 1],ll_word_list[16],-2054922799)
end if
if ll_wordarraycount + 8 > 0 and ll_wordarraycount + 8 <= upperbound(ll_temp) then
ll_a = this.of_ii(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 8],ll_word_list[13],1873313359)
end if
if ll_wordarraycount + 15 > 0 and ll_wordarraycount + 15 <= upperbound(ll_temp) then
ll_d = this.of_ii(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 15],ll_word_list[14],-30611744)
end if
if ll_wordarraycount + 6 > 0 and ll_wordarraycount + 6 <= upperbound(ll_temp) then
ll_c = this.of_ii(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 6],ll_word_list[15],-1560198380)
end if
if ll_wordarraycount + 13 > 0 and ll_wordarraycount + 13 <= upperbound(ll_temp) then
ll_b = this.of_ii(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 13],ll_word_list[16],1309151649)
end if
if ll_wordarraycount + 4 > 0 and ll_wordarraycount + 4 <= upperbound(ll_temp) then
ll_a = this.of_ii(ll_a,ll_b,ll_c,ll_d,ll_temp[ll_wordarraycount + 4],ll_word_list[13],-145523070)
end if
if ll_wordarraycount + 11 > 0 and ll_wordarraycount + 11 <= upperbound(ll_temp) then
ll_d = this.of_ii(ll_d,ll_a,ll_b,ll_c,ll_temp[ll_wordarraycount + 11],ll_word_list[14],-1120210379)
end if
if ll_wordarraycount + 2 > 0 and ll_wordarraycount + 2 <= upperbound(ll_temp) then
ll_c = this.of_ii(ll_c,ll_d,ll_a,ll_b,ll_temp[ll_wordarraycount + 2],ll_word_list[15],718787259)
end if
if ll_wordarraycount + 9 > 0 and ll_wordarraycount + 9 <= upperbound(ll_temp) then
ll_b = this.of_ii(ll_b,ll_c,ll_d,ll_a,ll_temp[ll_wordarraycount + 9],ll_word_list[16],-343485551)
end if
//中间结果向右位移
ll_a = this.of_addunsigned(ll_a,ll_aa)
ll_b = this.of_addunsigned(ll_b,ll_bb)
ll_c = this.of_addunsigned(ll_c,ll_cc)
ll_d = this.of_addunsigned(ll_d,ll_dd)
ll_wordarraycount = ll_wordarraycount + 16 - 1
loop
//生成128位散列值
ls_return = lower(this.of_wordtohex(ll_a) + this.of_wordtohex(ll_b) + this.of_wordtohex(ll_c) + this.of_wordtohex(ll_d))
return ls_return
end function
private function long of_f (readonly long al_x, readonly long al_y, readonly long al_z);
/*******************************************************************
函数名称:of_f()
参数: al_x long 值1
al_y long 值2
al_z long 值3
返回值: long 位运算结果
功能描述:md5加密时的位运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
return inv_numerical.of_bitwiseor(inv_numerical.of_bitwiseand(al_x,al_y),inv_numerical.of_bitwiseand((al_x + 1) * (-1),al_z))
end function
private function long of_ff (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac);/*******************************************************************
函数名称:of_ff()
参数: al_a long 值1
al_b long 值2
al_c long 值3
al_d long 值4
al_x long 值5
al_s long 值6
al_ac long 值7
返回值: long 运算结果
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
long ll_return
ll_return = this.of_f(al_b,al_c,al_d)
ll_return = this.of_addunsigned(ll_return,al_x)
ll_return = this.of_addunsigned(ll_return,al_ac)
ll_return = this.of_addunsigned(al_a,ll_return)
ll_return = this.of_rotateleft(ll_return,al_s)
ll_return = this.of_addunsigned(ll_return,al_b)
return ll_return
end function
private function long of_g (readonly long al_x, readonly long al_y, readonly long al_z);
/*******************************************************************
函数名称:of_g()
参数: al_x long 值1
al_y long 值2
al_z long 值3
返回值: long 位运算结果
功能描述:md5加密时的位运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
return inv_numerical.of_bitwiseor(inv_numerical.of_bitwiseand(al_x,al_z),inv_numerical.of_bitwiseand(al_y,(al_z + 1) * (-1)))
end function
private function long of_gg (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac);
/*******************************************************************
函数名称:of_gg()
参数: al_a long 值1
al_b long 值2
al_c long 值3
al_d long 值4
al_x long 值5
al_s long 值6
al_ac long 值7
返回值: long 运算结果
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
long ll_return
ll_return = this.of_g(al_b,al_c,al_d)
ll_return = this.of_addunsigned(ll_return,al_x)
ll_return = this.of_addunsigned(ll_return,al_ac)
ll_return = this.of_addunsigned(al_a,ll_return)
ll_return = this.of_rotateleft(ll_return,al_s)
ll_return = this.of_addunsigned(ll_return,al_b)
return ll_return
end function
private function long of_h (readonly long al_x, readonly long al_y, readonly long al_z);
/*******************************************************************
函数名称:of_h()
参数: al_x long 值1
al_y long 值2
al_z long 值3
返回值: long 位运算结果
功能描述:md5加密时的位运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
return inv_numerical.of_bitwisexor(inv_numerical.of_bitwisexor(al_x,al_y),al_z)
end function
private function long of_hh (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac);/*******************************************************************
函数名称:of_hh()
参数: al_a long 值1
al_b long 值2
al_c long 值3
al_d long 值4
al_x long 值5
al_s long 值6
al_ac long 值7
返回值: long 运算结果
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
long ll_return
ll_return = this.of_h(al_b,al_c,al_d)
ll_return = this.of_addunsigned(ll_return,al_x)
ll_return = this.of_addunsigned(ll_return,al_ac)
ll_return = this.of_addunsigned(al_a,ll_return)
ll_return = this.of_rotateleft(ll_return,al_s)
ll_return = this.of_addunsigned(ll_return,al_b)
return ll_return
end function
private function long of_i (readonly long al_x, readonly long al_y, readonly long al_z);
/*******************************************************************
函数名称:of_i()
参数: al_x long 值1
al_y long 值2
al_z long 值3
返回值: long 位运算结果
功能描述:md5加密时的位运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
return inv_numerical.of_bitwisexor(al_y,inv_numerical.of_bitwiseor(al_x,(al_z + 1) * (-1)))
end function
private function long of_ii (readonly long al_a, readonly long al_b, readonly long al_c, readonly long al_d, readonly long al_x, readonly long al_s, readonly long al_ac);
/*******************************************************************
函数名称:of_ii()
参数: al_a long 值1
al_b long 值2
al_c long 值3
al_d long 值4
al_x long 值5
al_s long 值6
al_ac long 值7
返回值: long 运算结果
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
long ll_return
ll_return = this.of_i(al_b,al_c,al_d)
ll_return = this.of_addunsigned(ll_return,al_x)
ll_return = this.of_addunsigned(ll_return,al_ac)
ll_return = this.of_addunsigned(al_a,ll_return)
ll_return = this.of_rotateleft(ll_return,al_s)
ll_return = this.of_addunsigned(ll_return,al_b)
return ll_return
end function
private function string of_wordtohex (readonly long al_value);
/*******************************************************************
函数名称:of_wordtohex()
参数: al_value long 原值
返回值: string 转化为十六进制后的值
功能描述:将数字转为十六进制值
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
string ls_return,ls_temp
long ll_temp,ll_count
ls_return = ''
ll_count = 0
do while ll_count < 4
ll_temp = inv_numerical.of_bitwiseand(this.of_rshift(al_value,ll_count * 8),255)
choose case integer(ll_temp / 16)
case 0 to 9
ls_temp = string(integer(ll_temp / 16))
case 10
ls_temp = 'a'
case 11
ls_temp = 'b'
case 12
ls_temp = 'c'
case 13
ls_temp = 'd'
case 14
ls_temp = 'e'
case 15
ls_temp = 'f'
case else
ls_temp = ''
end choose
ls_return = ls_return + ls_temp
choose case mod(ll_temp,16)
case 0 to 9
ls_temp = string(mod(ll_temp,16))
case 10
ls_temp = 'a'
case 11
ls_temp = 'b'
case 12
ls_temp = 'c'
case 13
ls_temp = 'd'
case 14
ls_temp = 'e'
case 15
ls_temp = 'f'
case else
ls_temp = ''
end choose
ls_return = ls_return + ls_temp
ll_count = ll_count + 1
loop
return ls_return
end function
private function long of_rshift (readonly long al_oldvalue, readonly long al_shiftbits);
/*******************************************************************
函数名称:of_rshift()
参数: al_oldvalue long 原值
al_shiftbits long 右移位数
返回值: long 右移指定位数后的值
功能描述:数值按位右移
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
ulong ll_return,ll_pos
string ls_value
//转成二进制
ls_value = inv_numerical.of_binary(al_oldvalue)
if al_oldvalue < 0 then
ls_value = midw(ls_value,2,lenw(ls_value))
ls_value = inv_numerical.of_bitwisenot(ls_value)
//低位加1
ll_pos = lastpos(ls_value,'0')
if ll_pos = 0 then
ls_value = fill('0',lenw(ls_value))
else
ls_value = leftw(ls_value,ll_pos - 1) + '1' + fill('0',lenw(ls_value) - ll_pos)
end if
ls_value = fill('1',32 - lenw(ls_value)) + ls_value
ll_return = inv_numerical.of_decimal(ls_value)
else
ll_return = al_oldvalue
end if
ll_return = long(ll_return / this.of_m2power(al_shiftbits))
//转成二进制
ls_value = inv_numerical.of_binary(ll_return)
if ll_return < 0 then
ls_value = midw(ls_value,2,lenw(ls_value))
ls_value = inv_numerical.of_bitwisenot(ls_value)
//低位加1
ll_pos = lastpos(ls_value,'0')
if ll_pos = 0 then
ls_value = fill('0',lenw(ls_value))
else
ls_value = leftw(ls_value,ll_pos - 1) + '1' + fill('0',lenw(ls_value) - ll_pos)
end if
ls_value = fill('1',32 - lenw(ls_value)) + ls_value
ll_return = inv_numerical.of_decimal(ls_value)
end if
ll_return = inv_numerical.of_bitwiseand(ll_return,-1)
return ll_return
end function
private function long of_rotateleft (readonly long al_oldvalue, readonly long al_shiftbits);
/*******************************************************************
函数名称:of_rotateleft()
参数: al_oldvalue long 原值
al_shiftbits long 左移位数
返回值: long 数据左移指定位数后的值
功能描述:数据左移指定位数
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
return inv_numerical.of_bitwiseor(this.of_lshift(al_oldvalue,al_shiftbits),this.of_rshift(al_oldvalue,32 - al_shiftbits))
end function
private function long of_monbits (readonly long al_oldvalue);
/*******************************************************************
函数名称:of_monbits()
参数: al_oldvalue long 原值
返回值: long 新值
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
if al_oldvalue >= 0 and al_oldvalue <= 30 then
return 2^(al_oldvalue + 1) - 1
else
return 0
end if
end function
private function long of_m2power (readonly long al_oldvalue);
/*******************************************************************
函数名称:of_m2power()
参数: al_oldvalue long 原值
返回值: long 新值
功能描述:md5加密时的运算之一
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
if al_oldvalue >= 0 and al_oldvalue <= 30 then
return 2^al_oldvalue
else
return 0
end if
end function
private function long of_lshift (readonly long al_oldvalue, readonly long al_shiftbits);
/*******************************************************************
函数名称:of_lshift()
参数: al_oldvalue long 原值
al_shiftbits long 左移位数
返回值: long 左移指定位数后的值
功能描述:数值按位左移
创建人: 康剑民
创建日期:2004-05-24
版本号: v1.0.0
*******************************************************************/
ulong ll_return,ll_pos
string ls_value
//转成二进制
ls_value = inv_numerical.of_binary(al_oldvalue)
if al_oldvalue < 0 then
ls_value = midw(ls_value,2,lenw(ls_value))
ls_value = inv_numerical.of_bitwisenot(ls_value)
//低位加1
ll_pos = lastpos(ls_value,'0')
if ll_pos = 0 then
ls_value = fill('0',lenw(ls_value))
else
ls_value = leftw(ls_value,ll_pos - 1) + '1' + fill('0',lenw(ls_value) - ll_pos)
end if
ls_value = fill('1',32 - lenw(ls_value)) + ls_value
ll_return = inv_numerical.of_decimal(ls_value)
else
ll_return = al_oldvalue
end if
ll_return = ll_return * this.of_m2power(al_shiftbits)
ll_return = inv_numerical.of_bitwiseand(ll_return,-1)
return ll_return
end function
private function integer of_getunicode (string as_char);
/*******************************************************************
函数名称:of_getunicode()
参数: as_char string 字符
返回值: long unicode编码
功能描述:取字符的unicode编码
创建人: 康剑民
创建日期:2004-05-24(第一版)
版本号: v1.0.0
*******************************************************************/
long ll_len_old,ll_len_new
long ll_return
ll_len_old = len(as_char)
ll_len_new = 2 * ll_len_old
MultiByteToWideChar(0, 0, as_char, ll_len_old, ll_return, ll_len_new)
if ll_return < 0 then ll_return = 65536 – abs(ll_return)
return ll_return
end function
on nvo_md5.create
call super::create
triggerevent( this, "constructor" )
end on
on nvo_md5.destroy
triggerevent( this, "destructor" )
call super::destroy
end on
以下是调用nvo_md5中of_encrypt()的测试结果:
参数1:’’
结果1:d41d8cd98f00b204e9800998ecf8427e
参数2:’a’
结果2:0cc175b9c0f1b6a831c399e269772661
参数3:’abc’
结果3:900150983cd24fb0d6963f7d28e17f72
参数4:’ab cd’
结果4:04a7d98b199aaaac0b3bebeae31e2bfc
参数5:’1’
结果5:c4ca4238a0b923820dcc509a6f75849b
参数6:’1234567890’
结果6:e807f1fcf82d132f9bb018ca6738a19f
参数7:’请’
结果7:06a4c398f66e05c94159cfeb601e185b
参数8:’請’
结果8:e11b4b598f8c28ee1b159cc218c7c059
参数9:’中国’
结果9:4c9370f4ddb0ff4862701ee019a58b46
参数10:’中国 china 086’
结果10:7b3104a9188e89f5c13de67c180a5f28
写作日期:2004-06-02