anyone here got a function to find is a string is base64 encoded?

Wouter wouter.abraham at pi.be
Sun Jul 25 15:14:52 EDT 2004


> 	• 	From: Mark Brownell
> 	• 	 Subject: Re: anyone here got a function to find is a string is  
> base64 encoded?
> 	• 	 Date: Sun, 25 Jul 2004 09:16:19 -0700
>
>
>> On Sunday, July 25, 2004, at 08:59 AM, [EMAIL PROTECTED] wrote:
>>
>>
>> What about...
>>
>>
>> try
>>   put base64decode(tStr) into tStr
>> catch errnum
>>   return ""
>> end try
>> return tStr
>>
>>  /H
>>

won't work

>
>  That's a good idea. What about this for a string test? Base64 is 72  
> characters per line. I suppose you could test for the number of  
> characters in each line.
>
>
> Mark


base64Decode is a very safe function.
Even if one deletes the "=" char(s) at the end of a base64Encoded  
string (if there are) it will decode correctly.
Even if one inserts chars (like ; or ? or  < or > etc.) in a   
base64Encoded string it will decode correctly.
Like :
      put  
base64Decode("U2VuZCB1c2UtcmV2b2x1dGl????vbiBtYWlsa!!!!! 
W5nIGxpc3Qgc3VibWlzc2lvbnMgdG8=")

(watch the mail wrap)

One could  test for a *welformed* base64Encodeded string :

function isWelformed64 pText
   replace cr with "" in pText
   if the num of chars in tText mod 4 = 0 then
      repeat for each char i in pText
       put i into tArray[i]
     end repeat
     put the keys of tArray into pText
     if "=" is in tKeys then
       put the num of chars in pText - 1 into x
       put 1 into tC
       repeat for each char i in pText
         if  i = "=" and tC < x then return false
         add 1 to tC
       end repeat
     end if
     repeat for each line i in tKeys
       if i is not in "abcdefghijklmnopqrstuvwxyz1234567890/=" then  
return false
     end repeat
     return true
   else return false
end isWelformed64

But if false it still could be a base64Encodeded string.
And if true it could still be a 1 word unencoded string.
But hey this is a quick starter.

Greetings,
WA


More information about the use-livecode mailing list