Write a simple encryption and decryption class with ASP. . . .

xiaoxiao2021-03-06  37

class Base64Classrem Const dim sBASE_64_CHARACTERS 'conversion code dim lenString' calculated length of the string dim iCount 'counter dim returnValue' return value dim tempChar 'character cache dim tempString' cache string dim paramString 'parameter string dim temHex' Cache Cache hexadecimal made dim tempLow 'cache low dim tempHigh' high cache dim mod3String 'dim mod4String' dim tempBinary 'dim tempByteOne' dim tempByteTwo 'dim tempByteThree' dim tempByteFour 'dim tempSaveBitsOne' dim tempSaveBitsTwo '' *********** *************************************************************************** ******************************** private sub Class_Initialize () sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 /" end sub '**** ******************************************* ****** ***** ************************************************** *********** ***************************************************************************** ******************************************* Private Sub class_terminate () SBASE_64_Characters = "" "" End Sub "***** ********************************************* ****** ****** ************************************************* *************************************************** The ANSI encoded string is Base64 Code '******************************************************* PUBLIC FUNCTION ENCODE paramString) tempString = "" returnValue = "" lenString = len (paramString) if lenString <1 then Encode = returnValue else mod3String = lenString mod 3 'is complementary digit for ease of calculation if mod3String> 0 then lenString = lenString 3-mod3String LENSTRING = LENSTRING-3 End if '********************************* Begin for iCount = 1 to Lenstring Step 3 Tempbinary =

Mid (paramString, iCount, 3) tempByteOne = Asc (Mid (tempBinary, 1, 1)): tempSaveBitsOne = tempByteOne And 3 tempByteTwo = Asc (Mid (tempBinary, 2, 1)): tempSaveBitsTwo = tempByteTwo And 15 tempChar = Asc ( Mid (tempBinary, 3, 1)) tempByteOne = Mid (sBASE_64_CHARACTERS, ((tempByteOne And 252) / 4) 1, 1) tempByteTwo = Mid (sBASE_64_CHARACTERS, (((tempByteTwo And 240) / 16) Or (tempSaveBitsOne * 16 ) And & HFF) 1, 1) tempByteThree = Mid (sBASE_64_CHARACTERS, (((tempChar And 192) / 64) Or (tempSaveBitsTwo * 4) And & HFF) 1, 1) tempByteFour = Mid (sBASE_64_CHARACTERS, (tempChar And 63) 1, 1) Tempstring = Tempbyteone & TempbyTwo & TempbyThree & Tempbytefour ReturnValue = ReturnValue & Tempstring Next '************************* ** ** *********************** BEGIN handles the last remaining characters if mod3string> 0 THEN TEMPBINARY = MID (paramstring, icount, mod3string) if mod3string = 1 Tempstring = Tempbinary & Chr (64) & chr (64) & chr (64) 'Use @ 号 补 位 数 ELSE TEMPSTRING = TEM PBINARY & CHR (64) & chr (64) 'End if returnvalue = returnvalue & tempstring end if' ****************************************************************** *** End Processing the last remaining characters ENCODE = RETURNVALUE END IF END FUNCTION '******************************************* ************* 'END performs Base64 encoded by ANSI encoded strings' ************************** *********************************************************** ************** 'END converts the base64 encoded string to ANSI encoded string' ******************************** ************************ Public function decode (paramstring) Tempstring = "ReturnValue =" "LENSTRING = LEN (paramstring) if lenstring <

1 THEN DECODE = RETURNVALUE ELSE MOD4STRING = LENSTRING MOD4STRING> 0 THEN 'string length should be 4 multiple decode = returnvalue else' begin Judgment is @ 号 IF MID (paramstring, lenstring-1, 1) = "@ "THEN MOD4STRING = 2 End if if Mid (paramstring, lenstring-2, 1) =" @ "THEN MOD4STRING = 1 end if 'End Judgment is @ 号 IF MOD4STRING> 0 THEN LENSTRING = LENSTRING-4 End IF' ** ************************************ Begin for iCount = 1 to Lenstring Step 4 Tempstring = MID (Paramstring, Icount, 4) Tempbyteone = INSTR (sBASE_64_CHARACTERS, Mid (tempString, 1, 1)) - 1 tempByteTwo = InStr (sBASE_64_CHARACTERS, Mid (tempString, 2, 1)) - 1 tempByteThree = InStr (sBASE_64_CHARACTERS, Mid (tempString, 3, 1)) - 1 tempByteFour = INSTR (SBASE_64_Characters, MID (TempString, 4, 1)) - 1 Tempbyteone = CHR ((TempBytetwo and 48) / 16) or (TempByteone * 4) and & HFF) Tempbytetwo = "" & chr (((TempbyThree and 60) / 4) OR (TempbyTwo * 16) And & HFF) TempbyThree = CHR ((((TempbyTH) Ree and 3) * 64) And & HFF) OR (Tempbytefour and 63)) Tempstring = Tempbyteone & TempbyTwo & TempbyThree ReturnValue = ReturnValue & Tempstring Next '**************************** ********** * End 'Handling the last remaining character if mod4string> 0 Tempstring = left (Right (paramstring, 4), mod4string ReturnValue = RETURNVALUE & TEMPSTRING End if decode = RETURNVALUE END IF End if End function '****************************************** END converts the base64 encoded string to ANSI encoded string '********************************************* ******** End Class simply implements an encryption and decryption in this class. The purpose is to share with you.

转载请注明原文地址:https://www.9cbs.com/read-83460.html

New Post(0)