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

 About This Book

 Base64 Encoding

 Base64 Encoding and Decoding Tools

 Base64URL - URL Safe Base64 Encoding

Base32 Encoding

 Base32 Encoding Algorithm

 Base32 Character Set Maps

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

 URL Encoding, URI Encoding, or Percent Encoding

 UUEncode Encoding

 References

 Full Version in PDF/EPUB