Friends, where can I found FWH functions.
Something like this: HB_BASE64DECODE( <cBase64> ) --> cString | Decodes a base 64 encoded character string.
Thank you very much
Regrads.
Ruben Dario Fernandez.
FUNCTION StrToBase64( cTexte )
LOCAL X, cHex, cTexte64 := ""
DO WHILE !( cTexte == "" )
cHex := ""
FOR X := 1 TO 3
cHex += CarToBin( LEFT(cTexte, 1) )
IF LEN(cTexte) > 1
cTexte := SUBSTR(cTexte, 2)
ELSE
cTexte := ""
EXIT
ENDIF
NEXT
FOR X := 1 TO 4
IF SUBSTR(cHex, ( (X - 1) * 6) + 1 ) == ""
cTexte64 += REPLICATE("=", 4 - X + 1)
EXIT
ELSE
IF LEN( cHex ) % 6 > 0
cHex += REPLICATE("0", 6 - ( LEN( cHex ) % 6 ) )
ENDIF
cTexte64 += Carac64( "00" + SUBSTR(cHex, ( (X - 1) * 6) + 1, 6 ) )
ENDIF
NEXT X
ENDDO
RETURN cTexte64
FUNCTION Base64ToStr( cTexte64 )
LOCAL X, cHex, cCar, cTexte := ""
DO WHILE !( cTexte64 == "" )
cCar := LEFT(cTexte64,4)
cHex := ""
FOR X := 1 TO 4
IF SUBSTR(cCar, X, 1 ) != "="
cHex += Hex64( SUBSTR(cCar, X, 1 ) )
ELSE
EXIT
ENDIF
NEXT X
FOR X := 1 TO 3
IF SUBSTR(cHex, ( (X - 1) * + 1 ) == ""
EXIT
ELSE
cTexte += BinToCar( SUBSTR(cHex, ( (X - 1) * + 1, 8 ) )
ENDIF
NEXT X
IF LEN(cTexte64) > 4
cTexte64 := SUBSTR(cTexte64, 5)
ELSE
cTexte64 := ""
ENDIF
ENDDO
//The function Base64toStr, has a error, the change is, add this code on the end function:
cTexte := str2hex(cTexte)
IF Right(cTexte,2)="00"
cTexte := SubStr(cTexte,1,len(cTexte)-2)
ENDIF
cTexte := Hex2Str(cTexte)
RETURN cTexte
FUNCTION Carac64( cBin )
LOCAL nPos := ASC( BinToCar( @cBin ) ) + 1
RETURN SUBSTR( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", nPos, 1)
FUNCTION Hex64( carac64 )
LOCAL cCodeAsc, nI, cRet
nI := AT(carac64, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" )
cCodeAsc := CHR( nI -1 )
cRet := SUBSTR( CarToBin( @cCodeAsc ) , 3, 6)
RETURN cRet
FUNCTION CarToBin( carac, lInverse )
#define cHexa "0123456789ABCDEF"
#define aBin {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }
LOCAL cToHex, cRet
IF EMPTY( lInverse )
cToHex := str2Hex( carac )
cRet := aBin[ AT( LEFT(cToHex,1), cHexa ) ] + aBin[ AT( SUBSTR(cToHex,2), cHexa ) ]
ELSE
cToHex := SUBSTR(cHexa, ASCAN(aBin, LEFT(carac,4) ), 1 ) + SUBSTR(cHexa, ASCAN(aBin, SUBSTR(carac,5,4) ), 1 )
cRet := Hex2str( cToHex )
ENDIF
RETURN cRet
FUNCTION BinToCar( cBin )
RETURN CarToBin( @cBin, .T. )
FUNCTION StrToBase64( cTexte )
LOCAL X, cHex, cTexte64 := ""
DO WHILE !( cTexte == "" )
cHex := ""
FOR X := 1 TO 3
cHex += CarToBin( LEFT(cTexte, 1) )
IF LEN(cTexte) > 1
cTexte := SUBSTR(cTexte, 2)
ELSE
cTexte := ""
EXIT
ENDIF
NEXT
FOR X := 1 TO 4
IF SUBSTR(cHex, ( (X - 1) * 6) + 1 ) == ""
cTexte64 += REPLICATE("=", 4 - X + 1)
EXIT
ELSE
IF LEN( cHex ) % 6 > 0
cHex += REPLICATE("0", 6 - ( LEN( cHex ) % 6 ) )
ENDIF
cTexte64 += Carac64( "00" + SUBSTR(cHex, ( (X - 1) * 6) + 1, 6 ) )
ENDIF
NEXT X
ENDDO
RETURN cTexte64
FUNCTION Base64ToStr( cTexte64 )
LOCAL X, cHex, cCar, cTexte := ""
DO WHILE !( cTexte64 == "" )
cCar := LEFT(cTexte64,4)
cHex := ""
FOR X := 1 TO 4
IF SUBSTR(cCar, X, 1 ) != "="
cHex += Hex64( SUBSTR(cCar, X, 1 ) )
ELSE
EXIT
ENDIF
NEXT X
FOR X := 1 TO 3
IF SUBSTR(cHex, ( (X - 1) * 8) + 1 ) == ""
EXIT
ELSE
cTexte += BinToCar( SUBSTR(cHex, ( (X - 1) * 8) + 1, 8 ) )
ENDIF
NEXT X
IF LEN(cTexte64) > 4
cTexte64 := SUBSTR(cTexte64, 5)
ELSE
cTexte64 := ""
ENDIF
ENDDO
//The function Base64toStr, has a error, the change is, add this code on the end function:
cTexte := str2hex(cTexte)
IF Right(cTexte,2)="00"
cTexte := SubStr(cTexte,1,len(cTexte)-2)
ENDIF
cTexte := Hex2Str(cTexte)
RETURN cTexte
FUNCTION Carac64( cBin )
LOCAL nPos := ASC( BinToCar( @cBin ) ) + 1
RETURN SUBSTR( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", nPos, 1)
FUNCTION Hex64( carac64 )
LOCAL cCodeAsc, nI, cRet
nI := AT(carac64, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" )
cCodeAsc := CHR( nI -1 )
cRet := SUBSTR( CarToBin( @cCodeAsc ) , 3, 6)
RETURN cRet
FUNCTION CarToBin( carac, lInverse )
#define cHexa "0123456789ABCDEF"
#define aBin {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }
LOCAL cToHex, cRet
IF EMPTY( lInverse )
cToHex := str2Hex( carac )
cRet := aBin[ AT( LEFT(cToHex,1), cHexa ) ] + aBin[ AT( SUBSTR(cToHex,2), cHexa ) ]
ELSE
cToHex := SUBSTR(cHexa, ASCAN(aBin, LEFT(carac,4) ), 1 ) + SUBSTR(cHexa, ASCAN(aBin, SUBSTR(carac,5,4) ), 1 )
cRet := Hex2str( cToHex )
ENDIF
RETURN cRet
FUNCTION BinToCar( cBin )
RETURN CarToBin( @cBin, .T. )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Otto and 28 guests