MD5加密算法的VB60类模块实例.docx

上传人:b****2 文档编号:17809817 上传时间:2023-08-04 格式:DOCX 页数:18 大小:29.68KB
下载 相关 举报
MD5加密算法的VB60类模块实例.docx_第1页
第1页 / 共18页
MD5加密算法的VB60类模块实例.docx_第2页
第2页 / 共18页
MD5加密算法的VB60类模块实例.docx_第3页
第3页 / 共18页
MD5加密算法的VB60类模块实例.docx_第4页
第4页 / 共18页
MD5加密算法的VB60类模块实例.docx_第5页
第5页 / 共18页
MD5加密算法的VB60类模块实例.docx_第6页
第6页 / 共18页
MD5加密算法的VB60类模块实例.docx_第7页
第7页 / 共18页
MD5加密算法的VB60类模块实例.docx_第8页
第8页 / 共18页
MD5加密算法的VB60类模块实例.docx_第9页
第9页 / 共18页
MD5加密算法的VB60类模块实例.docx_第10页
第10页 / 共18页
MD5加密算法的VB60类模块实例.docx_第11页
第11页 / 共18页
MD5加密算法的VB60类模块实例.docx_第12页
第12页 / 共18页
MD5加密算法的VB60类模块实例.docx_第13页
第13页 / 共18页
MD5加密算法的VB60类模块实例.docx_第14页
第14页 / 共18页
MD5加密算法的VB60类模块实例.docx_第15页
第15页 / 共18页
MD5加密算法的VB60类模块实例.docx_第16页
第16页 / 共18页
MD5加密算法的VB60类模块实例.docx_第17页
第17页 / 共18页
MD5加密算法的VB60类模块实例.docx_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

MD5加密算法的VB60类模块实例.docx

《MD5加密算法的VB60类模块实例.docx》由会员分享,可在线阅读,更多相关《MD5加密算法的VB60类模块实例.docx(18页珍藏版)》请在冰点文库上搜索。

MD5加密算法的VB60类模块实例.docx

MD5加密算法的VB60类模块实例

MD5加密算法的VB6.0类模块实例

Form1窗体及代码:

OptionExplicit

PrivateSubCommand1_Click()

Dimc1AsNewClass1

DimmAsString

Text2.Text=c1.DigestStrToHexStr(Text1.Text)

EndSub

PrivateSubForm_Load()

Text1.Text=""

Text2.Text=""

EndSub

调用的类模块代码如下:

OptionExplicit

PrivateConstOFFSET_4=4294967296#

PrivateConstMAXINT_4=2147483647

PrivateConstS11=7

PrivateConstS12=12

PrivateConstS13=17

PrivateConstS14=22

PrivateConstS21=5

PrivateConstS22=9

PrivateConstS23=14

PrivateConstS24=20

PrivateConstS31=4

PrivateConstS32=11

PrivateConstS33=16

PrivateConstS34=23

PrivateConstS41=6

PrivateConstS42=10

PrivateConstS43=15

PrivateConstS44=21

'=

'=ClassVariables

'=

PrivateState(4)AsLong

PrivateByteCounterAsLong

PrivateByteBuffer(63)AsByte

'=

'=ClassProperties

'=

PropertyGetRegisterA()AsString

RegisterA=State

(1)

EndProperty

PropertyGetRegisterB()AsString

RegisterB=State

(2)

EndProperty

PropertyGetRegisterC()AsString

RegisterC=State(3)

EndProperty

PropertyGetRegisterD()AsString

RegisterD=State(4)

EndProperty

'=

'=ClassFunctions

'=

'

'Functiontoquicklydigestafileintoahexstring

'

PublicFunctionDigestFileToHexStr(FileNameAsString)AsString

OpenFileNameForBinaryAccessReadAs#1

MD5Init

DoWhileNotEOF

(1)

Get#1,,ByteBuffer

IfLoc

(1)

(1)Then

ByteCounter=ByteCounter+64

MD5TransformByteBuffer

EndIf

Loop

ByteCounter=ByteCounter+(LOF

(1)Mod64)

Close#1

MD5Final

DigestFileToHexStr=GetValues

EndFunction

'

'Functiontodigestatextstringandoutputtheresultasastring

'ofhexadecimalcharacters.

'

PublicFunctionDigestStrToHexStr(SourceStringAsString)AsString

MD5Init

MD5UpdateLen(SourceString),StringToArray(SourceString)

MD5Final

DigestStrToHexStr=GetValues

EndFunction

'

'Autilityfunctionwhichconvertsastringintoanarrayof

'bytes.

'

PrivateFunctionStringToArray(InStringAsString)AsByte()

DimIAsInteger

DimbytBuffer()AsByte

ReDimbytBuffer(Len(InString))

ForI=0ToLen(InString)-1

bytBuffer(I)=Asc(Mid(InString,I+1,1))

NextI

StringToArray=bytBuffer

EndFunction

'

'Concatenatethefourstatevaulesintoonestring

'

PublicFunctionGetValues()AsString

GetValues=LongToString(State

(1))&LongToString(State

(2))&LongToString(State(3))&LongToString(State(4))

EndFunction

'

'ConvertaLongtoaHexstring

'

PrivateFunctionLongToString(NumAsLong)AsString

DimaAsByte

DimbAsByte

DimcAsByte

DimdAsByte

a=NumAnd&HFF&

Ifa<16Then

LongToString="0"&Hex(a)

Else

LongToString=Hex(a)

EndIf

b=(NumAnd&HFF00&)\256

Ifb<16Then

LongToString=LongToString&"0"&Hex(b)

Else

LongToString=LongToString&Hex(b)

EndIf

c=(NumAnd&HFF0000)\65536

Ifc<16Then

LongToString=LongToString&"0"&Hex(c)

Else

LongToString=LongToString&Hex(c)

EndIf

IfNum<0Then

d=((NumAnd&H7F000000)\16777216)Or&H80&

Else

d=(NumAnd&HFF000000)\16777216

EndIf

Ifd<16Then

LongToString=LongToString&"0"&Hex(d)

Else

LongToString=LongToString&Hex(d)

EndIf

EndFunction

'

'Initializetheclass

'Thismustbecalledbeforeadigestcalculationisstarted

'

PublicSubMD5Init()

ByteCounter=0

State

(1)=UnsignedToLong(1732584193#)

State

(2)=UnsignedToLong(4023233417#)

State(3)=UnsignedToLong(2562383102#)

State(4)=UnsignedToLong(271733878#)

EndSub

'

'MD5Final

'

PublicSubMD5Final()

DimdblBitsAsDouble

Dimpadding(72)AsByte

DimlngBytesBufferedAsLong

padding(0)=&H80

dblBits=ByteCounter*8

'Padout

lngBytesBuffered=ByteCounterMod64

IflngBytesBuffered<=56Then

MD5Update56-lngBytesBuffered,padding

Else

MD5Update120-ByteCounter,padding

EndIf

padding(0)=UnsignedToLong(dblBits)And&HFF&

padding

(1)=UnsignedToLong(dblBits)\256And&HFF&

padding

(2)=UnsignedToLong(dblBits)\65536And&HFF&

padding(3)=UnsignedToLong(dblBits)\16777216And&HFF&

padding(4)=0

padding(5)=0

padding(6)=0

padding(7)=0

MD5Update8,padding

EndSub

'Breakupinputstreaminto64bytechunks

'

PublicSubMD5Update(InputLenAsLong,InputBuffer()AsByte)

DimIIAsInteger

DimIAsInteger

DimJAsInteger

DimKAsInteger

DimlngBufferedBytesAsLong

DimlngBufferRemainingAsLong

DimlngRemAsLong

lngBufferedBytes=ByteCounterMod64

lngBufferRemaining=64-lngBufferedBytes

ByteCounter=ByteCounter+InputLen

'Useupoldbufferresultsfirst

IfInputLen>=lngBufferRemainingThen

ForII=0TolngBufferRemaining-1

ByteBuffer(lngBufferedBytes+II)=InputBuffer(II)

NextII

MD5TransformByteBuffer

lngRem=(InputLen)Mod64

'Thetransferisamultipleof64letsdosometransformations

ForI=lngBufferRemainingToInputLen-II-lngRemStep64

ForJ=0To63

ByteBuffer(J)=InputBuffer(I+J)

NextJ

MD5TransformByteBuffer

NextI

lngBufferedBytes=0

Else

I=0

EndIf

'Bufferanyremaininginput

ForK=0ToInputLen-I-1

ByteBuffer(lngBufferedBytes+K)=InputBuffer(I+K)

NextK

EndSub

'

'MD5Transform

'

PrivateSubMD5Transform(Buffer()AsByte)

Dimx(16)AsLong

DimaAsLong

DimbAsLong

DimcAsLong

DimdAsLong

a=State

(1)

b=State

(2)

c=State(3)

d=State(4)

Decode64,x,Buffer

'Round1

FFa,b,c,d,x(0),S11,-680876936

FFd,a,b,c,x

(1),S12,-389564586

FFc,d,a,b,x

(2),S13,606105819

FFb,c,d,a,x(3),S14,-1044525330

FFa,b,c,d,x(4),S11,-176418897

FFd,a,b,c,x(5),S12,1200080426

FFc,d,a,b,x(6),S13,-1473231341

FFb,c,d,a,x(7),S14,-45705983

FFa,b,c,d,x(8),S11,1770035416

FFd,a,b,c,x(9),S12,-1958414417

FFc,d,a,b,x(10),S13,-42063

FFb,c,d,a,x(11),S14,-1990404162

FFa,b,c,d,x(12),S11,1804603682

FFd,a,b,c,x(13),S12,-40341101

FFc,d,a,b,x(14),S13,-1502002290

FFb,c,d,a,x(15),S14,1236535329

'Round2

GGa,b,c,d,x

(1),S21,-165796510

GGd,a,b,c,x(6),S22,-1069501632

GGc,d,a,b,x(11),S23,643717713

GGb,c,d,a,x(0),S24,-373897302

GGa,b,c,d,x(5),S21,-701558691

GGd,a,b,c,x(10),S22,38016083

GGc,d,a,b,x(15),S23,-660478335

GGb,c,d,a,x(4),S24,-405537848

GGa,b,c,d,x(9),S21,568446438

GGd,a,b,c,x(14),S22,-1019803690

GGc,d,a,b,x(3),S23,-187363961

GGb,c,d,a,x(8),S24,1163531501

GGa,b,c,d,x(13),S21,-1444681467

GGd,a,b,c,x

(2),S22,-51403784

GGc,d,a,b,x(7),S23,1735328473

GGb,c,d,a,x(12),S24,-1926607734

'Round3

HHa,b,c,d,x(5),S31,-378558

HHd,a,b,c,x(8),S32,-2022574463

HHc,d,a,b,x(11),S33,1839030562

HHb,c,d,a,x(14),S34,-35309556

HHa,b,c,d,x

(1),S31,-1530992060

HHd,a,b,c,x(4),S32,1272893353

HHc,d,a,b,x(7),S33,-155497632

HHb,c,d,a,x(10),S34,-1094730640

HHa,b,c,d,x(13),S31,681279174

HHd,a,b,c,x(0),S32,-358537222

HHc,d,a,b,x(3),S33,-722521979

HHb,c,d,a,x(6),S34,76029189

HHa,b,c,d,x(9),S31,-640364487

HHd,a,b,c,x(12),S32,-421815835

HHc,d,a,b,x(15),S33,530742520

HHb,c,d,a,x

(2),S34,-995338651

'Round4

IIa,b,c,d,x(0),S41,-198630844

IId,a,b,c,x(7),S42,1126891415

IIc,d,a,b,x(14),S43,-1416354905

IIb,c,d,a,x(5),S44,-57434055

IIa,b,c,d,x(12),S41,1700485571

IId,a,b,c,x(3),S42,-1894986606

IIc,d,a,b,x(10),S43,-1051523

IIb,c,d,a,x

(1),S44,-2054922799

IIa,b,c,d,x(8),S41,1873313359

IId,a,b,c,x(15),S42,-30611744

IIc,d,a,b,x(6),S43,-1560198380

IIb,c,d,a,x(13),S44,1309151649

IIa,b,c,d,x(4),S41,-145523070

IId,a,b,c,x(11),S42,-1120210379

IIc,d,a,b,x

(2),S43,718787259

IIb,c,d,a,x(9),S44,-343485551

State

(1)=LongOverflowAdd(State

(1),a)

State

(2)=LongOverflowAdd(State

(2),b)

State(3)=LongOverflowAdd(State(3),c)

State(4)=LongOverflowAdd(State(4),d)

'/*Zeroizesensitiveinformation.

'*/

'MD5_memset((POINTER)x,0,sizeof(x));

EndSub

PrivateSubDecode(LengthAsInteger,OutputBuffer()AsLong,InputBuffer()AsByte)

DimintDblIndexAsInteger

DimintByteIndexAsInteger

DimdblSumAsDouble

intDblIndex=0

ForintByteIndex=0ToLength-1Step4

dblSum=InputBuffer(intByteIndex)+_

InputBuffer(intByteIndex+1)*256#+_

InputBuffer(intByteIndex+2)*65536#+_

InputBuffer(intByteIndex+3)*16777216#

OutputBuffer(intDblIndex)=UnsignedToLong(dblSum)

intDblIndex=intDblIndex+1

NextintByteIndex

EndSub

'

'FF,GG,HH,andIItransformationsforrounds1,2,3,and4.

'Rotationisseparatefromadditiontopreventrecomputation.

'

PrivateFunctionFF(aAsLong,_

bAsLong,_

cAsLong,_

dAsLong,_

xAsLong,_

sAsLong,_

acAsLong)AsLong

a=LongOverflowAdd4(a,(bAndc)Or(Not(b)Andd),x,ac)

a=LongLeftRotate(a,s)

a=LongOverflowAdd(a,b)

EndFunction

PrivateFunctionGG(aAsLong,_

bAsLong,_

cAsLong,_

dAsLong,_

xAsLong,_

sAsLong,_

acAsLong)AsLong

a=LongOverflowAdd4(a,(bAndd)Or(cAndNot(d)),x,ac)

a=LongLeftRotate(a,s)

a=LongOverflowAdd(a,b)

EndFunction

PrivateFunctionHH(aAsLong,_

bAsLong,_

cAsLong,_

dAsLong,_

xAsLong,_

sAsLong,_

acAsLong)AsLong

a=LongOverflowAdd4(a,bXorcXord,x,ac)

a=LongLeftRotate(a,s)

a=LongOverflowAdd(a,b)

EndFunction

PrivateFunctionII(aAsLong,_

bAsLong,_

cAsLong,_

dAsLong

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 学科竞赛

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2