Encoding and encryption are not the same. When we talk about encoding, we are talking about converting raw data (binary) into a format that can be stored or transmitted as text.
There are many popular ways to encode data as text. Some include:
Typically, it is a bad idea to create your own encoding scheme. However, for the sake of learning, we are going to create one for fun.
Encoding schemes have an alphabet. An alphabet is just the set of available characters in the scheme.
0123456789
0123456789abcdef
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
The number of characters in the alphabet is the "base". Base64 has 64 characters.
Binary integer literals are written in Go as follows:
// zeroWrittenInBinary is just an int with the value 0
zeroWrittenInBinary := 0b0000
fmt.Println(zeroWrittenInBinary)
// prints: 0
// oneWrittenInBinary is just an int with the value 1
oneWrittenInBinary := 0b0001
fmt.Println(oneWrittenInBinary)
// prints: 1
Complete the base8Char function. It accepts a single byte of data and returns the associated character from our alphabet: ABCDEFGH.
For example, given these binary numbers, it will return the following characters:
0000 -> A
0001 -> B
0010 -> C
0011 -> D
etc
Note that because we only have 8 characters in our alphabet, we will ignore any numbers equal to or greater than 8. Remember, an entire byte can contain the numbers 0 through 255.
byte to an integer using int().