Data Encoding Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
Bitpedia Implementation of Base32 in Java - Test
This section provides a test program for the Java implementation of the Base32 encoding algorithm by the Bitcollider project.
To test Java implementation of the Base32 encoding algorithm listed in the previous section, I wrote this simple testing program:
/* BitpediaBase32Test.java
* Copyright (c) 2010 HerongYang.com. All Rights Reserved.
*/
import java.io.*;
import org.bitpedia.util.*;
class BitpediaBase32Test {
public static void main(String[] a) {
if (a.length<1) {
System.out.println("Usage:");
System.out.println("java BitpediaBase32Test 1/2/3/4/5");
return;
}
String test = a[0];
String theInput = null;
String theExpected = null;
if (test.equals("1")) {
theInput = "A";
theExpected = "IE======";
} else if (test.equals("2")) {
theInput = "AB";
theExpected = "IFBA====";
} else if (test.equals("3")) {
theInput = "ABC";
theExpected = "IFBEG===";
} else if (test.equals("4")) {
theInput = "ABCD";
theExpected = "IFBEGRA=";
} else if (test.equals("5")) {
theInput = "ABCDE";
theExpected = "IFBEGRCF";
} else {
System.out.println("Usage:");
System.out.println("java BitpediaBase32Test 1/2/3/4/5");
return;
}
String theEncoded = Base32.encode(theInput.getBytes());
byte[] theDecoded = Base32.decode(theEncoded);
System.out.println("Input : "+theInput);
System.out.println("Encoded : "+theEncoded);
System.out.println("Expected: "+theExpected);
System.out.println("Decoded : "+new String(theDecoded));
return;
}
}
Here is the test result:
C:\herong\base32>javac BitpediaBase32Test.java C:\herong\base32>java BitpediaBase32Test 1 Input : A Encoded : IE Expected: IE====== Decoded : A C:\herong\base32>java BitpediaBase32Test 2 Input : AB Encoded : IFBA Expected: IFBA==== Decoded : AB C:\herong\base32>java BitpediaBase32Test 3 Input : ABC Encoded : IFBEG Expected: IFBEG=== Decoded : ABC C:\herong\base32>java BitpediaBase32Test 4 Input : ABCD Encoded : IFBEGRA Expected: IFBEGRA= Decoded : ABCD C:\herong\base32>java BitpediaBase32Test 5 Input : ABCDE Encoded : IFBEGRCF Expected: IFBEGRCF Decoded : ABCDE
As you can see from the test result, the Bitpedia implementation of the Base32 encoding algorithm does not add padding equal signs (=) as defined RFC 3548.
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++