|
VFP ·R¥ÎªÌªÀ°Ï ¥»°Q½×°Ï¬° Visual Foxpro ·R¥ÎªÌ¸gÅç¥æ¬yªº¦a¤è, ½Ð¦h¦h§Q¥Î"·j´M"ªº¥\¯à, ¥ý¬d¬Ý¬Ý¦³µL«e¨Ò¥i´`, ¦pªGÁÙ¦³¤£À´ªº¦Aµo°Ý. ³¡¥÷¥DÃD¦³ªþ¥[ÀÉ®×, ¶·¥ýµù¥U¦¨¬°ªÀ°Ï©~¥Á¤~¥i¥H¤U¸ü.
|
¤W¤@½g¥DÃD :: ¤U¤@½g¥DÃD |
µoªí¤H |
¤º®e |
garfield Site Admin
µù¥U®É¶¡: 2003-01-30 ¤å³¹: 2158
²Ä 1 ¼Ó
|
µoªí©ó: ¬P´Á¤T ¤C¤ë 08, 2009 6:11 pm ¤å³¹¥DÃD: vfp6 ¥i¥Îªº Base64 ½s½X/¸Ñ½Xµ{¦¡ |
|
|
¥»¨Ó·Q¥Î¦belleryq ¼gªºµ{¦¡, ¦ýµo²{vfp6¨Ã¤£¤ä´©¸ê®Æ«¬ºA¬OQªº¤G¶i¦ì¸ê®Æ,
http://blog.roodo.com/thinkingmore/archives/553966.html
©Ò¥H¥t¥~§ä¨ì
http://fox.wikis.com/wc.dll?Wiki~Base64~SoftwareEng
¦ý¬Oµo²{³oÓµ{¦¡¦³ÂI¤p·å²«,
¦b½s½X®É¤£¨¬3byte®É, ¶·¥Î=¶ñº¡¥¦, ¦Ó¤£¬O¥ÎA
©Ò¥H§ï¼g¥¦µ¹¦³¶·nªº¤H¥Î.¨Ã¼W±j¥¦ªº¥\¯à, Åý¥¦°£¤F¶ÇÀɦW¤§¥~¤]¥i¥H¶Ç¦r¦ê.
¥N½X: |
*!* *************************************************
*!* * Sample code, including timing test
*!* *************************************************
*!* LOCAL loBase64
*!* loBase64 = CREATEobject("Base64")
*!* strtofile('¸ê®Æ¨Ó·½http://fox.wikis.com/wc.dll?Wiki~Base64~SoftwareEng,µ{¦¡×§ï: garfield','c:\a.txt')
*!* ?"----------------"
*!* WITH loBase64
*!* lnSeconds = SECONDS()
*!* .Encode("c:\a.txt", "c:\base64.txt")
*!* ?SECONDS() - lnSeconds
*!* .Encode("c:\a.txt")
*!* ? .Encodestr
*!* .Encode(filetostr("c:\a.txt"), .t.) &&--¶Ç¨Ó±ý½s½Xªº¦r¦ê®É, ²Ä2ӰѼÆn¶Ç¨Ó .t.
*!* ? .Encodestr
*!* ?SECONDS() - lnSeconds
*!* lnSeconds = SECONDS()
*!* IF .not. .Decode("c:\___base64.txt", "c:\b.txt")
*!* ? .errorcode
*!* ENDIF
*!* IF .not. .Decode("c:\base64.txt", "czxc:\b.txt")
*!* ? .errorcode
*!* ENDIF
*!* .Decode("c:\base64.txt", "c:\b.txt")
*!* .Decode("c:\base64.txt")
*!* *? .Decodestr
*!* ?SECONDS() - lnSeconds
*!* ENDWITH
*!* *************************************************
DEFINE Class Base64 As Custom
DIMENSION aBase64[64]
Encodestr=''
Decodestr=''
errorcode=''
*********************************************************************************
PROCEDURE Encode(tcInFile, tcOutFile)
*********************************************************************************
*
* Method: Encode()
*
* Purpose: Converts the specified file to Base64 encoding
*
* Remarks:
*
*******************************************************************************
* Character variables
LOCAL ;
lcBase64, ;
lcLine, ;
lcStr, ;
lcBin
* Integer variables
LOCAL ;
liDecimal, ;
liHandle, ;
i, ;
j
this.errorcode='' &&--¦pªG¦³°ÝÃD·|¦³¿ù»~¦r¦ê
IF vartype(tcOutFile)='L' .and. tcOutFile &&--«ü©w tcInFile ¬°¤@Ó¦r¦ê¦Ó«DÀɦW
this.Decodestr = tcInFile
ELSE
* Only proceed if the specified file exists
IF !FILE(tcInFile)
this.errorcode= '§ä¤£¨ìÀÉ®×:'+tcInFile
ELSE
* Set some starting values
this.Decodestr = FILETOSTR(tcInFile)
ENDIF
ENDIF
IF empty(this.errorcode)
lcBase64 = ""
this.Encodestr = ""
* Get the characters from the input
* file, in groups of three each
FOR i = 1 TO LEN(this.Decodestr) STEP 3
lcStr = SUBSTR(this.Decodestr, i, 3)
* Encode the binary code to Base64 and
* add it to the existing output string
lcBase64 = lcBase64 + This.Split4(lcStr)
ENDFOR
* Build the encoded output string,
* in lines of 76 characters each
FOR i = 1 TO LEN(lcBase64) STEP 76
this.Encodestr = this.Encodestr + SUBSTR(lcBase64, i, 76) + chr(13)+chr(10)
ENDFOR
if !empty(this.Encodestr)
this.Encodestr = left(this.Encodestr,len(this.Encodestr)-2)
endif
IF vartype(tcOutFile)='C' &&--¦³¶ÇÀɦW¨Ó, ªí¥Ün«Ø¥ßÀÉ®×
* Create the output file, overwriting it if it exists
liHandle = FCREATE(tcOutFile)
* Only proceed if we could create the output file
IF liHandle > 0
* Write & close the output file
FWRITE(liHandle, this.Encodestr)
FCLOSE(liHandle)
ELSE
this.errorcode= 'µLªk«Ø¥ßÀÉ®×:'+tcOutFile
ENDIF
ENDIF
ENDIF
mret = empty( this.errorcode)
RETURN mret
ENDPROC
*********************************************************************************
PROCEDURE Decode(tcInFile, tcOutFile)
*********************************************************************************
*
* Method: Decode()
*
* Purpose: Converts the specified file from Base64 encoding
*
* Remarks: Input file must contain no extra characters
* other than Base64 encoded characters, and each
* line must be exactly 76 characters long
*
*******************************************************************************
* Character variables
LOCAL ;
lcString, ;
lcBinary, ;
lcChr, ;
lcBin
* Integer variables
LOCAL ;
liHandle, ;
liDec, ;
i, ;
j
this.errorcode= ''
IF vartype(tcOutFile)='L' .and. tcOutFile &&--«ü©w tcInFile ¬°¤@Ó¦r¦ê¦Ó«DÀɦW
this.Encodestr = tcInFile
ELSE
* Only proceed if the specified file exists
IF !FILE(tcInFile)
this.errorcode= '§ä¤£¨ìÀÉ®×:'+tcInFile
ELSE
* Set some starting values
this.Encodestr = FILETOSTR(tcInFile)
ENDIF
ENDIF
IF empty(this.errorcode)
this.Decodestr = ""
* Strip out linefeeds, so we have
* one continous string to process
this.Encodestr = CHRTRAN(this.Encodestr, chr(13)+chr(10), "")
* Get the characters from the input
* file, in groups of four each
FOR i = 1 TO LEN(this.Encodestr) STEP 4
lcString =strt( SUBSTR(this.Encodestr, i, 4),'=','') &&--¥h±¼¶ñº¡4Óbyteªº½X¼Æ=
WITH This
for j=1 to len(lcString)
lcString = stuff( lcString , j,1,CHR(ASCAN(.aBase64, SUBSTR(lcString, j, 1)) - 1))
*!* lcString = ;
*!* CHR(ASCAN(.aBase64, SUBSTR(lcString, 1, 1)) - 1) + ;
*!* CHR(ASCAN(.aBase64, SUBSTR(lcString, 2, 1)) - 1) + ;
*!* CHR(ASCAN(.aBase64, SUBSTR(lcString, 3, 1)) - 1) + ;
*!* CHR(ASCAN(.aBase64, SUBSTR(lcString, 4, 1)) - 1)
next
* Decode the binary code from Base64
* and build the existing output string
this.Decodestr = this.Decodestr + .Split3(lcString)
ENDWITH
ENDFOR
IF vartype(tcOutFile)='C' &&--¦³¶ÇÀɦW¨Ó, ªí¥Ün«Ø¥ßÀÉ®×
* Create the output file, overwriting it if it exists
liHandle = FCREATE(tcOutFile)
* Only proceed if we could create the output file
IF liHandle > 0
* Write & close the output file
FWRITE(liHandle, this.Decodestr)
FCLOSE(liHandle)
ELSE
this.errorcode= 'µLªk«Ø¥ßÀÉ®×:'+tcOutFile
ENDIF
ENDIF
ELSE
this.errorcode= '§ä¤£¨ìÀÉ®×:'+tcInFile
ENDIF
mret = empty( this.errorcode)
RETURN mret
ENDPROC
*********************************************************************************
Hidden PROCEDURE Split3(tcBinary)
*********************************************************************************
*
* Method: Split3()
*
* Purpose: Splits a 24-bit binary string into 3 8-bit
* strings, converts them into decimal values and
* returns them as concatenated ASCII characters
*
* Remarks:
*
*******************************************************************************
WITH This
LOCAL ;
liOutByte1, ;
liOutByte2, ;
liOutByte3, ;
liInByte1, ;
liInByte2, ;
liInByte3, ;
liInByte4
liInByte1 = ASC(SUBSTR(tcBinary, 1, 1))
liInByte2 = ASC(SUBSTR(tcBinary, 2, 1))
liInByte3 = ASC(SUBSTR(tcBinary, 3, 1))
liInByte4 = ASC(SUBSTR(tcBinary, 4, 1))
liOutByte1 = BITLSHIFT(BITAND(liInByte1, 0x3f), 2) + BITRSHIFT(liInByte2, 4)
liOutByte2 = BITLSHIFT(BITAND(liInByte2, 0x0f), 4) + BITRSHIFT(liInByte3, 2)
liOutByte3 = BITLSHIFT(BITAND(liInByte3, 0x03), 6) + BITAND(liInByte4, 0x3f)
RETURN ;
CHR(liOutByte1) + ;
CHR(liOutByte2) + ;
CHR(liOutByte3)
ENDWITH
ENDPROC
*********************************************************************************
Hidden PROCEDURE Split4(tcBinary)
*********************************************************************************
*
* Method: Split4()
*
* Purpose: Splits a 24-bit binary string into 4 6-bit
* strings, converts them into decimal values and
* returns them as concatenated Base64 characters
*
* Remarks:
*
*******************************************************************************
LOCAL ;
liOutByte1, ;
liOutByte2, ;
liOutByte3, ;
liOutByte4, ;
liInByte1, ;
liInByte2, ;
liInByte3,;
mret
*mret = '====' &&--ªø«×¤£¨¬3Ó¦rªº¬Ò¥Î= ¨Ó¨ú¥N, ¤£¥i¥H¥Î0 ==>A
liInByte1 = ASC(SUBSTR(tcBinary, 1, 1))
liInByte2 = ASC(SUBSTR(tcBinary, 2, 1))
liInByte3 = ASC(SUBSTR(tcBinary, 3, 1))
liOutByte1 = BITRSHIFT(liInByte1, 2)
liOutByte2 = BITLSHIFT(BITAND(liInByte1, 0x03), 4) + BITRSHIFT(BITAND(liInByte2, 0xf0), 4)
liOutByte3 = BITLSHIFT(BITAND(liInByte2, 0x0f), 2) + BITRSHIFT(BITAND(liInByte3, 0xc0), 6)
liOutByte4 = BITAND(liInByte3, 0x3f)
WITH This
mret = ;
.aBase64[liOutByte1 + 1] + ;
.aBase64[liOutByte2 + 1] + ;
.aBase64[liOutByte3 + 1] + ;
.aBase64[liOutByte4 + 1]
ENDWITH
return left(mret, len(tcBinary)+1)+repl('=',3-len(tcBinary))
ENDPROC
*********************************************************************************
Hidden PROCEDURE Init()
*********************************************************************************
*
* Method: Init()
*
* Purpose:
*
* Remarks: Build the encode/decode array, based
* on the following Base64 lookup table
*
* -------------------------------------------
* | 0 = A | 16 = Q | 32 = g | 48 = w |
* | 1 = B | 17 = R | 33 = h | 49 = x |
* | 2 = C | 18 = S | 34 = i | 50 = y |
* | 3 = D | 19 = T | 35 = j | 51 = z |
* | 4 = E | 20 = U | 36 = k | 52 = 0 |
* | 5 = F | 21 = V | 37 = l | 53 = 1 |
* | 6 = G | 22 = W | 38 = m | 54 = 2 |
* | 7 = H | 23 = X | 39 = n | 55 = 3 |
* | 8 = I | 24 = Y | 40 = o | 56 = 4 |
* | 9 = J | 25 = Z | 41 = p | 57 = 5 |
* | 10 = K | 26 = a | 42 = q | 58 = 6 |
* | 11 = L | 27 = b | 43 = r | 59 = 7 |
* | 12 = M | 28 = c | 44 = s | 60 = 8 |
* | 13 = N | 29 = d | 45 = t | 61 = 9 |
* | 14 = O | 30 = e | 46 = u | 62 = + |
* | 15 = P | 31 = f | 47 = v | 63 = / |
* -------------------------------------------
*
*******************************************************************************
LOCAL i
FOR i = 0 TO 25
this.aBase64[i + 1] = CHR(i + 65)
ENDFOR
FOR i = 26 TO 51
this.aBase64[i + 1] = CHR(i + 71)
ENDFOR
FOR i = 52 TO 61
this.aBase64[i + 1] = CHR(i - 4)
ENDFOR
this.aBase64[63] = "+"
this.aBase64[64] = "/"
ENDPROC
ENDDEFINE
|
_________________ §Q¥Î>>·j´M<<ªº¥\¯à·|¤ñ°ÝªºÁÙn§Ö±o¨ìµª®×. |
|
¦^³»ºÝ |
|
|
goto-dream
µù¥U®É¶¡: 2004-05-11 ¤å³¹: 909
²Ä 2 ¼Ó
|
|
¦^³»ºÝ |
|
|
garfield Site Admin
µù¥U®É¶¡: 2003-01-30 ¤å³¹: 2158
²Ä 3 ¼Ó
|
µoªí©ó: ¬P´Á¤T ¤Q¤@¤ë 11, 2009 1:53 pm ¤å³¹¥DÃD: |
|
|
vfp6 µLªk¥Î13ªº°Ñ¼Æ. _________________ §Q¥Î>>·j´M<<ªº¥\¯à·|¤ñ°ÝªºÁÙn§Ö±o¨ìµª®×. |
|
¦^³»ºÝ |
|
|
goto-dream
µù¥U®É¶¡: 2004-05-11 ¤å³¹: 909
²Ä 4 ¼Ó
|
|
¦^³»ºÝ |
|
|
ssyun
µù¥U®É¶¡: 2024-03-27 ¤å³¹: 3
²Ä 5 ¼Ó
|
µoªí©ó: ¬P´Á¤G ¥|¤ë 09, 2024 12:27 pm ¤å³¹¥DÃD: |
|
|
¦U¦ì¥ý¶i½Ð°Ý¤@¤U,¤W±base64½s½Xµ{¦¡,¤]¥i¥Hª½±µ¹ï¬F©²µoªº¾ÌÃÒÀɪ½±µ½s½X¶Ü?
¦]¬°§Ú½s§¹¤]¤£ª¾¹D¦p¦óÅçÃҹ藍¹ï? |
|
¦^³»ºÝ |
|
|
|
|
±z µLªk ¦b³oÓª©±µoªí¤å³¹ ±z µLªk ¦b³oÓª©±¦^ÂФ峹 ±z µLªk ¦b³oÓª©±½s¿è¤å³¹ ±z µLªk ¦b³oÓª©±§R°£¤å³¹ ±z µLªk ¦b³oÓª©±¶i¦æ§ë²¼ ±z µLªk ¦b³oÓª©±ªþ¥[ÀÉ®× ±z µLªk ¦b³oÓª©±¤U¸üÀÉ®×
|
Powered by phpBB © 2001, 2005 phpBB Group ¥¿Å餤¤å»y¨t¥Ñ phpbb-tw ºûÅ@»s§@
|