Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

CBellucci (Programmer)
13 Dec 11 12:04
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?
GriffMG (Programmer)
13 Dec 11 12:08
I am no expert on this, but a quick google got me this:

http://fox.wikis.com/wc.dll?Wiki~VfpBase64

Which has both encode and decode functions.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

GriffMG (Programmer)
13 Dec 11 12:21
Actually, the decode looks very like yours!

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

Helpful Member!  brigmar (Programmer)
13 Dec 11 12:41
I don't know the base64 specs, but:
 + = CHR(43), so ch = 43

This falls through the nested IIFs, assigning -1 to q, which appears to be a terminator.

The function is expecting the terminator to be the '=' character (ASCII 61). Any other character just forces the function to return an empty string.

Ok, so I just checked the specs, and reviewing the fox.wikis.com link.

The implementation of the decode function does not mirror the implementation of the encode function.

The encode function has + and / as characters 62 and 63 of the 'alphabet'.
The decode function recognises '/' (ASCII 47) and assigns it 63, but does not recognise '+' (ASCII 43)

Try replacing the embedded IIFs thusly:

CODE

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)))))

 
CBellucci (Programmer)
13 Dec 11 13:34
That did it! Thank you, thank you, thank you!!!

Now I can continue on with my project... You're a lifesaver!
brigmar (Programmer)
13 Dec 11 17:13
Weird that the author would use the basechars string to encode, but not to decode (using AT())

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close