DQ NO.1 - dragon quest fans club

 找回密碼
 加入成為夥伴
搜索
熱搜: 活動 交友 discuz
查看: 5570|回復: 0

[ASP] Base64 編碼 使用Classic ASP

[複製鏈接]
發表於 2014-9-16 10:00:37 | 顯示全部樓層 |閱讀模式
本文用於存放一份使用Classic ASP進行Base64編碼與解碼的Function程式碼



程式碼來源:http://www.freevbcode.com/ShowCode.asp?ID=5248


  1. ' Functions to provide encoding/decoding of strings with Base64.
  2. '
  3. ' Encoding: myEncodedString = base64_encode( inputString )
  4. ' Decoding: myDecodedString = base64_decode( encodedInputString )
  5. '
  6. ' Programmed by Markus Hartsmar for ShameDesigns in 2002.
  7. ' Email me at: mark@shamedesigns.com
  8. ' Visit our website at: http://www.shamedesigns.com/
  9. '

  10.         Dim Base64Chars
  11.         Base64Chars =        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
  12.                         "abcdefghijklmnopqrstuvwxyz" & _
  13.                         "0123456789" & _
  14.                         "+/"


  15.         ' Functions for encoding string to Base64
  16.         Public Function base64_encode( byVal strIn )
  17.                 Dim c1, c2, c3, w1, w2, w3, w4, n, strOut
  18.                 For n = 1 To Len( strIn ) Step 3
  19.                         c1 = Asc( Mid( strIn, n, 1 ) )
  20.                         c2 = Asc( Mid( strIn, n + 1, 1 ) + Chr(0) )
  21.                         c3 = Asc( Mid( strIn, n + 2, 1 ) + Chr(0) )
  22.                         w1 = Int( c1 / 4 ) : w2 = ( c1 And 3 ) * 16 + Int( c2 / 16 )
  23.                         If Len( strIn ) >= n + 1 Then
  24.                                 w3 = ( c2 And 15 ) * 4 + Int( c3 / 64 )
  25.                         Else
  26.                                 w3 = -1
  27.                         End If
  28.                         If Len( strIn ) >= n + 2 Then
  29.                                 w4 = c3 And 63
  30.                         Else
  31.                                 w4 = -1
  32.                         End If
  33.                         strOut = strOut + mimeencode( w1 ) + mimeencode( w2 ) + _
  34.                                           mimeencode( w3 ) + mimeencode( w4 )
  35.                 Next
  36.                 base64_encode = strOut
  37.         End Function

  38.         Private Function mimeencode( byVal intIn )
  39.                 If intIn >= 0 Then
  40.                         mimeencode = Mid( Base64Chars, intIn + 1, 1 )
  41.                 Else
  42.                         mimeencode = ""
  43.                 End If
  44.         End Function       


  45.         ' Function to decode string from Base64
  46.         Public Function base64_decode( byVal strIn )
  47.                 Dim w1, w2, w3, w4, n, strOut
  48.                 For n = 1 To Len( strIn ) Step 4
  49.                         w1 = mimedecode( Mid( strIn, n, 1 ) )
  50.                         w2 = mimedecode( Mid( strIn, n + 1, 1 ) )
  51.                         w3 = mimedecode( Mid( strIn, n + 2, 1 ) )
  52.                         w4 = mimedecode( Mid( strIn, n + 3, 1 ) )
  53.                         If w2 >= 0 Then _
  54.                                 strOut = strOut + _
  55.                                         Chr( ( ( w1 * 4 + Int( w2 / 16 ) ) And 255 ) )
  56.                         If w3 >= 0 Then _
  57.                                 strOut = strOut + _
  58.                                         Chr( ( ( w2 * 16 + Int( w3 / 4 ) ) And 255 ) )
  59.                         If w4 >= 0 Then _
  60.                                 strOut = strOut + _
  61.                                         Chr( ( ( w3 * 64 + w4 ) And 255 ) )
  62.                 Next
  63.                 base64_decode = strOut
  64.         End Function

  65.         Private Function mimedecode( byVal strIn )
  66.                 If Len( strIn ) = 0 Then
  67.                         mimedecode = -1 : Exit Function
  68.                 Else
  69.                         mimedecode = InStr( Base64Chars, strIn ) - 1
  70.                 End If
  71.         End Function
複製代碼
您需要登錄後才可以回帖 登錄 | 加入成為夥伴

本版積分規則

Archiver|手機版|ぱふぱふ屋|DQ NO.1

GMT+8, 2024-4-19 06:29 , Processed in 0.026449 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回復 返回頂部 返回列表