Base64 Encoding Challenge in Go

GoGoBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

This challenge aims to test your knowledge of base64 encoding in Golang.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL go(("`Go`")) -.-> go/AdvancedTopicsGroup(["`Advanced Topics`"]) go/AdvancedTopicsGroup -.-> go/base64_encoding("`base64 Encoding`") subgraph Lab Skills go/base64_encoding -.-> lab-15375{{"`Base64 Encoding Challenge in Go`"}} end

Base64 Encoding

You are required to write a Golang program that encodes and decodes a given string using both standard and URL-compatible base64 encoding.

Requirements

  • The program should import the encoding/base64 package with the b64 name instead of the default base64.
  • The program should encode the given string using both standard and URL-compatible base64 encoding.
  • The program should decode the encoded string using both standard and URL-compatible base64 decoding.
  • The program should print the encoded and decoded strings to the console.

Example

## The string encodes to slightly different values with the
## standard and URL base64 encoders (trailing `+` vs `-`)
## but they both decode to the original string as desired.
$ go run base64-encoding.go
YWJjMTIzIT8kKiYoKSctPUB+
abc123!?$*&()'-=@~

YWJjMTIzIT8kKiYoKSctPUB-
abc123!?$*&()'-=@~

Summary

In this challenge, you learned how to encode and decode a given string using both standard and URL-compatible base64 encoding in Golang.

Other Go Tutorials you may like