[Gambas-user] Base64 encoder routine needed for Yahoo smtp AUTH LOGIN

Pablo Vera pvera at ...729...
Mon Sep 12 14:54:12 CEST 2005


This is what I use...

--code------------------------------------------------------------------------------------
PUBLIC FUNCTION ToBase64(S AS String) AS String
DIM L AS Integer
DIM I AS Integer
DIM P AS Integer
DIM B AS Integer
DIM SS AS String
DIM SSS AS String
DIM TB64 AS String
DIM Table AS String
DIM Buf AS Byte
DIM Lim AS Integer

   TB64 = ""
   Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
   P = 1
   DO
     SS = Mid$(S, P, 3)
     L = Len(SS)
     SELECT CASE L
     CASE 0
       SSS = ""
       Lim = 0
       B = 0
     CASE 1
       SSS = "=="
       Lim = 2
       B = Shl(Asc(Mid$(SS, 1, 1)), 4)
     CASE 2
       SSS = "="
       Lim = 3
       B = Shl(Asc(Mid$(SS, 1, 1)), 12) + Shl(Asc(Mid$(SS, 2, 1)), 2)
     CASE 3
       SSS = ""
       Lim = 4
       B = Shl(Asc(Mid$(SS, 1, 1)), 16) + Shl(Asc(Mid$(SS, 2, 1)), 8) + Asc(Mid$(SS, 3, 1))
     END SELECT

     FOR I = 1 TO Lim
       Buf = B AND 63 ' 111111
       SSS = Mid$(Table, Buf + 1, 1) & SSS
       B = B \ 64
     NEXT

     TB64 = TB64 & SSS
     P = P + 3
   LOOP UNTIL L < 3

   RETURN TB64
END
------------------------------------------------------------------------------------------

Saludos,
Pablo Vera

Father Jarvis wrote:
> Hi, I'm trying to write an email client. Yahoo SMTP servers need base64
> encrypted
> username and password for logins. I have it working, by using an online
> base64 encoder
> and entering my encrypted username and password into the program, but
> I'd like to have some way for my program to encode these for the user.
> 
> I'm not advanced enough yet to do this, can anyone help with a little
> sub  that'll do it?
> 
> Thanks
> 
> pezz




More information about the User mailing list