Wiki Home

Base 64

Namespace: VB
-- Base64 --

Encode binary files to text streams and back again. Base64 is the file attachment encoding standard used by most email clients in support of MIME (Multi-purpose Internet Mail Extensions), per RFC-1521, RFC-1522 and RFC-2045.

Ankit Fadia provides a clear and helpful explanation of Base64 at his website:

The site has been gone for a long time now, but the above base64.htm file is available here

In VFP8+:
  • STRCONV(cExpression, 13) - Converts single-byte characters in cExpression to encoded base64 binary.
  • STRCONV(cExpression, 14) - Converts single-byte characters in cExpression to decoded base64 binary. The builtin function in VFP8 is significantly faster than the fastest (Base64e) code posted below.

    In VFP7-:
  • Jeff Bowman has written a VFP rendition of Base64:
    Suggestions for speed improvement are welcome. Suggestions may be sent to
  • Another Vfp Base 64 function.
    Here are timings for the five classes implemented in

    The 193K .zip file used in the bechmarks is

    Base64a shows how efficient string management and proper use of low level I/O functions can be done in FoxPro. Long iterations in the form of StringVar = StringVar + String are to be avoided, especially when the length of StringVar exceeds 64K. Use of the buffer management of the low level I/O functions eliminates the excessive string copying and garbage collection caused by the StringVar = StringVar + String technique. Base64b is just to illustrate how the STRTOFILE() and FILETOSTR() are more appropriate than low level I/O functions when you are writing the file with a single write.

    The optimizations I sent previously improved performance by a factor of ~6. Base64a improves performance by an additional factor of ~10. Base64c replaces the array lookups with string lookups that speed up encoding marginally and decoding very well. In Base64d CHRTRAN() is not used because of the performance degradation with empty target strings. Base64e uses the Fox Crypto FLL library that wraps Wei Dai's public domain Crypto++ - a free C++ class library of cryptographic schemes.
    Base64 Class Runtime Statistics
    Class Name Method Name Run Count Min. Run Time Max. Run Time Avg. Run Time
    Base64 Decode 5 45.1550 53.9880 49.1150
    Base64a Decode 5 6.0390 6.1690 6.0908
    Base64b Decode 5 44.9240 59.6450 51.3278
    Base64c Decode 5 3.3050 3.4150 3.3750
    Base64d Decode 5 1.9030 1.9830 1.9350
    Base64e Decode 5 0.0900 0.1610 0.1324
    Base64 Encode 5 30.3130 33.5080 31.7154
    Base64a Encode 5 3.7050 3.8850 3.7832
    Base64b Encode 5 31.2040 36.3230 33.0534
    Base64c Encode 5 3.0840 3.2150 3.1284
    Base64d Encode 5 3.1040 3.8350 3.3188
    Base64e Encode 5 0.0500 0.1410 0.0684

    - Albert Ballinger
    Category Web Development Category Code Samples
  • ( Topic last updated: 2011.11.03 04:10:04 AM )