Data Encoding Tutorials - Herong's Tutorial Examples - v5.22, by Herong Yang
Goetz' Implementation of Base64 in JavaScript - Test
This section provides a test program for the JavaScript implementation of the Base64 encoding algorithm by Goetz Heller.
To test JavaScript implementation of the Base64 encoding algorithm listed in the previous section, I wrote this simple testing page:
<html> <!-- JavaScript_Base64_Test.html -- Copyright (c) 2007 HerongYang.com. All Rights Reserved. --> <head> <title>JavaScript Base64 Test</title> <script type="text/javascript" src="Goetz_Base64.js"></script> </head> <body> <pre> <script type="text/javascript"> document.write('\nTest 1:\n'); test("A", "QQ=="); document.write('\nTest 2:\n'); test("AB", "QUI="); document.write('\nTest 3:\n'); test("ABC", "QUJD"); function test(theInput, theExpected) { theEncoded = base64.encode(theInput,false,false); theDecoded = base64.decode(theEncoded,1,false,true); document.write(' Input : '+theInput+'\n'); document.write(' Encoded : '+theEncoded+'\n'); document.write(' Expected: '+theExpected+'\n'); document.write(' Decoded : '+theDecoded+'\n'); } </script> </pre> </body> </html>
If you open the test page in a browser, you will see:
Test 1: Input : A Encoded : QQ== Expected: QQ== Decoded : A Test 2: Input : AB Encoded : QUI= Expected: QUI= Decoded : AB Test 3: Input : ABC Encoded : QUJD Expected: QUJD Decoded : ABC
The result matches my expectation perfectly.
Table of Contents
RFC 1421 - Privacy Enhancement for Email
RFC 1521 - MIME (Multipurpose Internet Mail Extensions)
W3C Implementation of Base64 in Java
Sun Implementation of Base64 in Java
Sun Implementation of Base64 in Java - Test
Goetz' Implementation of Base64 in JavaScript
►Goetz' Implementation of Base64 in JavaScript - Test
Base64 Encoding and Decoding Tools
Base64URL - URL Safe Base64 Encoding