Pure Programmer
Blue Matrix


Cluster Map

Project: Base64 Decoding

[[Base64]] is a binary-to-text encoding scheme used in the early days of computing when SMTP (email) and other network protocols only supported 7-bit bytes. It is still used today for attachments to email files. The idea is to convert a file that uses 8-bit bytes into a stream of 7-bit ASCII characters. By using a radix of 64 we can represent 6-bit values with one of the characters A-Z, a-z, 0-9, +, /. So the idea is to break three octets up into four sextets, then convert the sextet to one of our 64 7-bit safe ASCII characters. Depending on the length of the data one or two equal signs '=' will need to be output at the end to pad the output to an even multiple of four. Also to make things easier to read, a newline is output after every 76 output characters.

Write a program that accepts a filename on the command line of a Base64 encoded file, converts the file back to its original binary representation and outputs it to a second filename supplied on the command line.

See Base64Encoding

Output
$ javac -Xlint Base64Decoding.java $ java -ea Base64Decoding ../../data/text/GettysburgAddress.txt.b64 output/testBase64Decoding.txt $ diff ../../data/text/GettysburgAddress.txt output/testBase64Decoding.txt $ javac -Xlint Base64Decoding.java $ java -ea Base64Decoding ../../data/text/UnicodeTest.utf8.b64 output/testBase64Decoding.utf8 $ diff ../../data/text/UnicodeTest.utf8 output/testBase64Decoding.utf8 $ javac -Xlint Base64Decoding.java $ java -ea Base64Decoding ../../data/text/GlowingCat.jpg.b64 output/testBase64Decoding.jpg $ diff ../../data/images/GlowingCat.jpg output/testBase64Decoding.jpg

Solution