public function string of_compute (string as_password);ulong m[], lv
long ll_len, ll_full
long i, j, k
/*首先需要对信息进行填充,使其字节长度对512求余的结果等于448。
因此,信息的字节长度(bits length)将被扩展至n*512+448,即n*64+56个字节(bytes),
n为一个正整数。填充的方法如下,在信息的后面填充一个1和无数个0,
直到满足上面的条件时才停止用0对信息的填充。
然后,在在这个结果后面附加一个以64位二进制表示的填充前信息长度。
经过这两步的处理,现在的信息字节长度=n*512+448+64=(n+1)*512,即长度恰好是512的整数倍。
*/
ll_len = len(as_password)
ll_full = long(ll_len / MD5_BYTESIZE) * MD5_BYTESIZE + MD5_BYTESIZE
k = mod(ll_len,MD5_BYTESIZE)
if k > 56 then ll_full += MD5_BYTESIZE
if k <> 56 then as_password = as_password + char(128)
m[ll_full / 4 - 1] = BitShl( ll_len, 3)
m[ll_full / 4] = BitShr( ll_len, 29)
//
k = 1
ll_len = len(as_password)
for i = 1 to ll_len
m[k] = BitShl(asc(mid(as_password,i,1)),j) + m[k]
j += 8
if j = 32 then
k ++
j = 0
end if
next
//
ulong a, b, c, d, aa, bb, cc, dd
a += aa; b += bb; c += cc; d += dd
k += 16
next
return lower(pof_hex(a) + pof_hex(b) + pof_hex(c) + pof_hex(d))
end function
public subroutine ii (ref unsignedlong la, unsignedlong lb, unsignedlong lc, unsignedlong ld, unsignedlong mj, unsignedlong s, unsignedlong ti);//ly xor ( lx or (not lz));
la += BitXor( lc, BitOr( lb, BitNot(ld) ) ) + mj + ti
la = lb + BitRol(la,s)
end subroutine
public subroutine gg (ref unsignedlong la, unsignedlong lb, unsignedlong lc, unsignedlong ld, unsignedlong mj, unsignedlong s, unsignedlong ti);//(lb and ld) or (lc and(not ld));
la += BitOr( BitAnd(lb, ld), BitAnd(lc,BitNot(ld)) ) + mj + ti
la = lb + BitRol(la,s)
end subroutine
public subroutine ff (ref unsignedlong la, unsignedlong lb, unsignedlong lc, unsignedlong ld, unsignedlong mj, unsignedlong s, unsignedlong ti);la += BitOr( BitAnd(lb,lc), BitAnd( BitNot(lb), ld) ) + mj + ti
la = lb + BitRol(la,s)
end subroutine
public subroutine hh (ref unsignedlong la, unsignedlong lb, unsignedlong lc, unsignedlong ld, unsignedlong mj, unsignedlong s, unsignedlong ti);//lx xor ly xor lz;
la += BitXor( BitXor( lb, lc ), ld ) + mj + ti
la = lb + BitRol(la,s)
end subroutine
protected function string pof_hex (unsignedlong k);string lr
//交换位置
lr = of_dec2hex(k)
lr = mid(lr,7,2) + mid(lr,5,2) + mid(lr,3,2) + mid(lr,1,2)
return lr
end function
on nvo_ez_md5.create
TriggerEvent( this, "constructor" )
end on
on nvo_ez_md5.destroy
TriggerEvent( this, "destructor" )
end on
$PBExportHeader$nvo_ez_bitwise.sru
$PBExportComments$二进制位操作
forward
global type nvo_ez_bitwise from nonvisualobject
end type
end forward
global type nvo_ez_bitwise from nonvisualobject autoinstantiate
end type
type prototypes
end prototypes
type variables
end variables
forward prototypes
public function string of_dec2bin (unsignedlong k)
public function ulong of_bin2dec (readonly string as_bin)
public subroutine of_dec2bin (ulong k, ref ulong r[32])
public function string of_dec2hex (unsignedlong k)
public function ulong of_hex2dec (readonly string as_hex)
public function unsignedlong bitshr (unsignedlong k, integer bit)
public function unsignedlong bitshl (unsignedlong k, integer bit)
public function unsignedlong bitnot (unsignedlong k)
public function unsignedlong bitrol (unsignedlong k, unsignedlong bit)
public function ulong bitand (ulong k1, ulong k2)
public function ulong bitor (ulong k1, ulong k2)
public function ulong bitxor (ulong k1, ulong k2)
end prototypes
public function string of_dec2bin (unsignedlong k);string ls
long i, ld
ld = 1
for i = 1 to 31
if mod(k,ld + ld) >= ld then
ls = '1' + ls
else
ls = '0' + ls
end if
ld += ld
next
if k >= ld then return '1' + ls
return '0' + ls
end function
public function ulong of_bin2dec (readonly string as_bin);ulong lr, ld = 1
long i
for i = 32 to 1 step -1
if mid( as_bin, i, 1) = '1' then
lr += ld
end if
ld += ld
next
return lr
end function
public subroutine of_dec2bin (ulong k, ref ulong r[32]);long i
ulong ll
ll = 1
for i = 1 to 31
if mod(k,ll + ll) >= ll then r[i] = ll
ll += ll
next
if k >= ll then r[i] = ll
end subroutine
public function string of_dec2hex (unsignedlong k);char Hex[0 to 15] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}
string ls
do while k > 0
ls = Hex[mod(k, 16)] + ls
k /= 16
loop
return ls
end function
public function ulong of_hex2dec (readonly string as_hex);constant int C0 = asc('0')
constant int CA = asc('A')
constant int CAs = asc('a')
ulong k, ld = 1
int lc, i
for i = len(as_hex) to 1 step -1
lc = asc(mid(as_hex,i,1))
if lc > CA then
k += ld * (lc - CA + 10)
elseif lc > CAs then
k += ld * (lc - CAs + 10)
else
k += ld * (lc - C0)
end if
ld *= 16
next
return k
end function
public function unsignedlong bitshr (unsignedlong k, integer bit);return k / (2^bit)
end function
public function unsignedlong bitshl (unsignedlong k, integer bit);return k * 2^bit
end function
public function unsignedlong bitnot (unsignedlong k);return 4294967295 - k
end function
public function unsignedlong bitrol (unsignedlong k, unsignedlong bit);return BitShl(k,bit) + BitShr(k,32 - bit)
end function
public function ulong bitand (ulong k1, ulong k2);ulong lm = 1, lr
do
if mod(k1,lm + lm) >= lm then
if mod(k2,lm + lm) >= lm then lr += lm
end if
lm += lm
if k1 < lm then return lr
if k2 < lm then return lr
if lm = 2147483648 then return lr + lm
loop while true
end function
public function ulong bitor (ulong k1, ulong k2);ulong lm = 1, lr
do
if mod(k1,lm + lm) >= lm then
lr += lm
elseif mod(k2,lm + lm) >= lm then
lr += lm
end if
lm += lm
if k1 < lm then
if k2 < lm then return lr
end if
if lm = 2147483648 then return lr + lm
loop while true
end function
public function ulong bitxor (ulong k1, ulong k2);ulong lm = 1, lr
do
if (mod(k1,lm + lm) >= lm) <> (mod(k2,lm + lm) >= lm) then lr += lm
lm += lm
if k1 < lm then
if k2 < lm then return lr
end if
if lm = 2147483648 then
if (k1 < lm) <> (k2 < lm) then return lr + lm
return lr
end if
loop while true
end function
on nvo_ez_bitwise.create
TriggerEvent( this, "constructor" )
end on
on nvo_ez_bitwise.destroy
TriggerEvent( this, "destructor" )
end on