I know I can encode and decode Base64 strings using STRCONV in VFP9. Unfortunately, I'm tied to VFP6 for this project.
I have an Encode function that works great. I've decoded the strings in VFP9 using STRCONV and get the image I'm expecting.
So far, though, I've not found a Decode function that I can get to work. The following code "dies" (q < 0) on a + character:
FUNCTION DECSTR64
PARAMETERS S
LOCAL i,j,j,k,q,ch,s2,buf,tmpc
tmpc = 0
j = 0
buf = 0
s2 = ''
k = LEN(s)
FOR i = 1 TO k
ch = ASC(SUBSTR(s,i,1))
q = IIF((ch >= 97 AND ch <=122),25+ch-96,IIF((ch >= 65 AND ch <=90),ch-65,;
IIF((ch >= 48 AND ch <=57),ch+4,IIF(ch = 47,63,-1))))
IF q < 0 THEN
RETURN IIF(ch = 61,s2,'')
ENDIF
buf = BITOR(BITLSHIFT(buf,6),q)
j = j + 6
IF j >= 8 THEN
j = j - 8
tmpc = CHR(BITAND(BITRSHIFT(buf,j),255))
buf = BITAND(buf,BITLSHIFT(1,j) -1)
s2 = s2 + tmpc
ENDIF
ENDFOR
RETURN s2
ENDFUNC
Again, this function takes a Base64 string and decodes it to binary. Can anyone help?
I have an Encode function that works great. I've decoded the strings in VFP9 using STRCONV and get the image I'm expecting.
So far, though, I've not found a Decode function that I can get to work. The following code "dies" (q < 0) on a + character:
FUNCTION DECSTR64
PARAMETERS S
LOCAL i,j,j,k,q,ch,s2,buf,tmpc
tmpc = 0
j = 0
buf = 0
s2 = ''
k = LEN(s)
FOR i = 1 TO k
ch = ASC(SUBSTR(s,i,1))
q = IIF((ch >= 97 AND ch <=122),25+ch-96,IIF((ch >= 65 AND ch <=90),ch-65,;
IIF((ch >= 48 AND ch <=57),ch+4,IIF(ch = 47,63,-1))))
IF q < 0 THEN
RETURN IIF(ch = 61,s2,'')
ENDIF
buf = BITOR(BITLSHIFT(buf,6),q)
j = j + 6
IF j >= 8 THEN
j = j - 8
tmpc = CHR(BITAND(BITRSHIFT(buf,j),255))
buf = BITAND(buf,BITLSHIFT(1,j) -1)
s2 = s2 + tmpc
ENDIF
ENDFOR
RETURN s2
ENDFUNC
Again, this function takes a Base64 string and decodes it to binary. Can anyone help?