Data Encoding Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
Andre's Implementation of Base32 in PHP - Test
This section provides a test program for the PHP implementation of the Base32 encoding algorithm by Andre DeMarre.
To test PHP implementation of the Base32 encoding algorithm listed in the previous section, I wrote this simple testing program:
<?php # FixedBitNotation_test.php # Copyright (c) 2010 HerongYang.com. All Rights Reserved. # include("FixedBitNotation.php"); echo "\nTest 1:\n"; test("A", "IE======"); echo "\nTest 2:\n"; test("AB", "IFBA===="); echo "\nTest 3:\n"; test("ABC", "IFBEG==="); echo "\nTest 4:\n"; test("ABCD", "IFBEGRA="); echo "\nTest 5:\n"; test("ACBDE", "IFBEGRCF"); function test($theInput, $theExpected) { // RFC 4648 Base32 alphabet $base32 = new FixedBitNotation (5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', TRUE, TRUE); $theEncoded = $base32->encode($theInput); $theDecoded = $base32->decode($theEncoded); echo " Input : $theInput\n"; echo " Encoded : $theEncoded\n"; echo " Expected: $theExpected\n"; echo " Decoded : $theDecoded\n"; } ?>
Here is the test result:
C:\herong\base32>php FixedBitNotationTest.php Test 1: Input : A Encoded : IE====== Expected: IE====== Decoded : A Test 2: Input : AB Encoded : IFBA==== Expected: IFBA==== Decoded : AB Test 3: Input : ABC Encoded : IFBEG=== Expected: IFBEG=== Decoded : ABC Test 4: Input : ABCD Encoded : IFBEGRA= Expected: IFBEGRA= Decoded : ABCD Test 5: Input : ACBDE Encoded : IFBUERCF Expected: IFBEGRCF Decoded : ACBDE
The result matches my expectation perfectly.
Table of Contents
Base64 Encoding and Decoding Tools
Base64URL - URL Safe Base64 Encoding
Bitpedia Implementation of Base32 in Java
Bitpedia Implementation of Base32 in Java - Test
Andre's Implementation of Base32 in PHP
►Andre's Implementation of Base32 in PHP - Test
madebits Implementation of Base32 in C++