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
$ swiftc Base64Decoding.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ diff ../../data/text/GettysburgAddress.txt output/testBase64Decoding.txt diff: output/testBase64Decoding.txt: No such file or directory $ swiftc Base64Decoding.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ diff ../../data/text/UnicodeTest.utf8 output/testBase64Decoding.utf8 diff: output/testBase64Decoding.utf8: No such file or directory $ swiftc Base64Decoding.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ diff ../../data/images/GlowingCat.jpg output/testBase64Decoding.jpg diff: output/testBase64Decoding.jpg: No such file or directory

Solution