Using ASP to write a simple encryption and decryption class, in this class simple implementation of a cryptographic and decryption. The purpose is to share with you. The cracking of this class is very simple. Just look at my notes and see what's going on. The next time you write a Java encryption and decryption class.
Class Base64class
REM Const
Dim sbase_64_characters Conversion Code
Dim lenstring Calculates the length of a string
Dim icount Counter
Dim returnvalue Return Value
Dim Tempchar Cached Characters
Dim tempstring Cache String
Dim paramstring Parameter String
Dim Temhex Cache Cache Hex
Dim Templow Cache Low
Dim Temphigh Cache High
Dim mod3string
Dim mod4string
Dim tempbinary
Dim Tempbyteone
Dim tempbytetwo
Dim tempbytethree
Dim tempbytefour
Dim Tempsavebitsone
Dim tempsavebitstwo
********************************************
Begin Initialization Class
********************************************
Private Sub Class_Initialize ()
Sbase_64_characters=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz09+/endsub
********************************************
End Initialization class
********************************************
********************************************
Begin destroying class
********************************************
Private Sub Class_Terminate ()
Sbase_64_characters= End Sub
********************************************
End Destroy class
********************************************
********************************************
Begin BASE64 encoding an ANSI-encoded string
********************************************
Public Function Encode (paramstring)
tempstring=
Returnvalue=
Lenstring=len (paramstring)
If Lenstring<1 Then
Encode=returnvalue
Else
Mod3string=lenstring MoD 3
The number of complements is for easy calculation.
If Mod3string>0 Then
Lenstring=lenstring+3-mod3string
Lenstring=lenstring-3
Begin
For Icount=1 to lenstring step 3
Tempbinary = Mid (paramstring, icount, 3)
Response.Write Tempbinary
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) Or (Tempsavebitsone *) and &HFF) + 1, 1)
Tempbytethree = Mid (Sbase_64_characters, (Tempchar) Or (Tempsavebitstwo * 4) and &HFF) + 1, 1)
Tempbytefour = Mid (Sbase_64_characters, (Tempchar and 63) +1,1)
tempstring = tempbyteone & tempbytetwo &tempByteThree& tempbytefour Returnvalue=returnvalue & Tempstringnext
End
The last few remaining characters to begin processing
If Mod3string>0 Then
Tempbinary = Mid (paramstring, icount, mod3string)
If Mod3string=1 Then
tempstring = tempbinary & Chr ($) & Chr ($) &CHR (64) complement digits with @ number
else tempstring = tempbinary & Chr ($) &CHR (64) complement digits with @ number
End If
Returnvalue=returnvalue & TempString
End If
End processing the last remaining few characters
Encode=returnvalue End If End function
********************************************
End BASE64 encoding an ANSI-encoded string
********************************************
********************************************
End converts the BASE64 encoded string to an ANSI-encoded string
********************************************
Public Function Decode (paramstring)
tempstring=
Returnvalue=
Lenstring=len (paramstring)
If Lenstring<1 Then
Decode=returnvalue
Else
Mod4string=lenstring MoD 4
If mod4string >0 then string length should be a multiple of 4
Decode=returnvalue
Else begin to judge is not the @ number
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 not the @ number
If Mod4string>0 Then
Lenstring=lenstring-4
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) Or (Tempbyteone *4) and &hff) Tempbytetwo = & Chr (((Tempbytethree and 6 0) 4) Or (Tempbytetwo *) and &HFF)
Tempbytethree = Chr ((Tempbytethree and 3) *) and &HFF) Or (Tempbytefour and 63))
Tempstring=tempbyteone & Tempbytetwo & Tempbytethree
Returnvalue=returnvalue & TempString
Next
End
Processing the last remaining few characters
If mod4string > 0 Then
Tempstring=center (center (paramstring,4), mod4string)
returnvalue = returnvalue & tempstring
End If
Decode=returnvalue
End If
End If
End Function
********************************************
End converts the BASE64 encoded string to an ANSI-encoded string
********************************************
Author: CSDN Pxjianke