Alaska Software Inc. - base64 utility
Username: Password:
AuthorTopic: base64 utility
Nestor Guidobase64 utility
on Sat, 07 Nov 2009 19:13:26 +0200
Hi all

Does anyone have a string coverter to make a string base64?
any help in this regards would greatly be appreciated.

Kind regards,
Nestor
Frans VermeulenRe: base64 utility
on Sun, 08 Nov 2009 00:11:04 +0100
Nestor,

See below,

HTH,
Frans Vermeulen

///----------------------------------------------------------------------------
Function VstBase64Decode(cCoded)
///----------------------------------------------------------------------------
   Static Base64CodeBase:=; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
   Local  cBase64   :=AllTrim(cCoded)
   Local  nDataLen  :=Len(cBase64)
   Local  cRetVal   :=''
   Local  nGroep    :=0
   Local  nDataBytes:=0
   Local  nChar     :=0
   Local  cChar     :=''
   Local  nAt       :=0
   Local  nData     :=0

   nChar:=nDataLen%4
   If nChar>0
      nDataLen-=nChar
      cBase64 :=Left(cBase64,Len(cBase64)-nChar)
      Return ''      volledig corrupt...
   EndIf

    Elke groep van 4 karakters bevat 3 echte karakters
   For nGroep := 0 To nDataLen-4 Step 4
       filter van elk karakter de 6 significante bits van de data
       en tel dat op bij nData
       karakter '=' is opvuller

      nDataBytes := 3
      nData      := 0
      For nChar:=1 To 4

         cChar :=SubStr(cBase64, nGroep+nChar, 1)
         nData *=64
         If cChar=="="
            nDataBytes--
         Else
            nAt:=At(cChar,Base64CodeBase)-1
            If nAt<0
               nAt:=0
               Return ''
            EndIf
            nData+=nAt
         EndIf
      Next nChar

       Convert 3-byte integer into up To 3 characters
      If nDataBytes>0; cRetVal+=Chr( nData/65536     ); EndIf
      If nDataBytes>1; cRetVal+=Chr((nData%65536)/256); EndIf
      If nDataBytes>2; cRetVal+=Chr( nData%256       ); EndIf
   Next nGroep

Return AllTrim(cRetVal)

///----------------------------------------------------------------------------
Function VstBase64Encode(cToCode)
///----------------------------------------------------------------------------
   Static Base64CodeBase:=; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
   Local  cNormaal  :=AllTrim(cToCode)
   Local  nDataLen  :=Len(cNormaal)
   Local  cRetVal   :=''
   Local  cTemp     :=''
   Local  nGroep    :=0
   Local  nChar     :=0
   Local  nData     :=0

   nChar:=nDataLen%3
   If nChar>0
      cNormaal+=Space(3-nChar)
   EndIf
   nDataLen:=Len(cNormaal)

   For nGroep := 0 To nDataLen-3 Step 3

      nData      := 0
      For nChar:=1 To 3
         nData*=256
         nData+=Asc(SubStr(cNormaal, nGroep+nChar))
      Next nChar

      cTemp:=''
      For nChar:=1 To 4
         cTemp:=SubStr(Base64CodeBase,(nData%64)+1,1)+cTemp
         nData:=Int(nData/64)
      Next nChar
      cRetVal+=cTemp
   Next nGroep

Return AllTrim(cRetVal)


> Hi all
> 
> Does anyone have a string coverter to make a string base64?
> any help in this regards would greatly be appreciated.
> 
> Kind regards,
> Nestor
> 
>
Nestor GuidoRe: base64 utility
on Sun, 08 Nov 2009 09:33:45 +0200
Hi Frans,

Thank you ever so much...from what i see and have tested this is working 
perfectly.....

Kind Regards,
Nestor

<Frans Vermeulen> wrote in message 
news:20091108001104.bb5597d8.fvermeulen@7iggo.nl...
> Nestor,
>
> See below,
>
> HTH,
> Frans Vermeulen
>
> ///----------------------------------------------------------------------------
> Function VstBase64Decode(cCoded)
> ///----------------------------------------------------------------------------
>   Static Base64CodeBase:=; 
> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
>   Local  cBase64   :=AllTrim(cCoded)
>   Local  nDataLen  :=Len(cBase64)
>   Local  cRetVal   :=''
>   Local  nGroep    :=0
>   Local  nDataBytes:=0
>   Local  nChar     :=0
>   Local  cChar     :=''
>   Local  nAt       :=0
>   Local  nData     :=0
>
>   nChar:=nDataLen%4
>   If nChar>0
>      nDataLen-=nChar
>      cBase64 :=Left(cBase64,Len(cBase64)-nChar)
>      Return ''      volledig corrupt...
>   EndIf
>
>    Elke groep van 4 karakters bevat 3 echte karakters
>   For nGroep := 0 To nDataLen-4 Step 4
>       filter van elk karakter de 6 significante bits van de data
>       en tel dat op bij nData
>       karakter '=' is opvuller
>
>      nDataBytes := 3
>      nData      := 0
>      For nChar:=1 To 4
>
>         cChar :=SubStr(cBase64, nGroep+nChar, 1)
>         nData *=64
>         If cChar=="="
>            nDataBytes--
>         Else
>            nAt:=At(cChar,Base64CodeBase)-1
>            If nAt<0
>               nAt:=0
>               Return ''
>            EndIf
>            nData+=nAt
>         EndIf
>      Next nChar
>
>       Convert 3-byte integer into up To 3 characters
>      If nDataBytes>0; cRetVal+=Chr( nData/65536     ); EndIf
>      If nDataBytes>1; cRetVal+=Chr((nData%65536)/256); EndIf
>      If nDataBytes>2; cRetVal+=Chr( nData%256       ); EndIf
>   Next nGroep
>
> Return AllTrim(cRetVal)
>
> ///----------------------------------------------------------------------------
> Function VstBase64Encode(cToCode)
> ///----------------------------------------------------------------------------
>   Static Base64CodeBase:=; 
> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
>   Local  cNormaal  :=AllTrim(cToCode)
>   Local  nDataLen  :=Len(cNormaal)
>   Local  cRetVal   :=''
>   Local  cTemp     :=''
>   Local  nGroep    :=0
>   Local  nChar     :=0
>   Local  nData     :=0
>
>   nChar:=nDataLen%3
>   If nChar>0
>      cNormaal+=Space(3-nChar)
>   EndIf
>   nDataLen:=Len(cNormaal)
>
>   For nGroep := 0 To nDataLen-3 Step 3
>
>      nData      := 0
>      For nChar:=1 To 3
>         nData*=256
>         nData+=Asc(SubStr(cNormaal, nGroep+nChar))
>      Next nChar
>
>      cTemp:=''
>      For nChar:=1 To 4
>         cTemp:=SubStr(Base64CodeBase,(nData%64)+1,1)+cTemp
>         nData:=Int(nData/64)
>      Next nChar
>      cRetVal+=cTemp
>   Next nGroep
>
> Return AllTrim(cRetVal)
>
>
>> Hi all
>>
>> Does anyone have a string coverter to make a string base64?
>> any help in this regards would greatly be appreciated.
>>
>> Kind regards,
>> Nestor
>>
>>