Pure Programmer
Blue Matrix


Cluster Map

Project: Base64 Encoding

[[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, converts the file to Base64 and outputs it to the console.

See Base64Decoding

Output
$ swiftc Base64Encoding.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) $ swiftc Base64Encoding.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) $ swiftc Base64Encoding.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)

Solution