Skip to content

Instantly share code, notes, and snippets.

@krlicmuhamed
Last active July 22, 2022 13:03
Show Gist options
  • Save krlicmuhamed/b2b7e65bf61a16330cd30cf6478e08e3 to your computer and use it in GitHub Desktop.
Save krlicmuhamed/b2b7e65bf61a16330cd30cf6478e08e3 to your computer and use it in GitHub Desktop.
Decode a base64 string in FoxPro
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,IIF(ch=43,62,-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment