Member-only story
Learn base64 Encoding and SHA-256/SHAKE-256 Hashing in Python
Understand the fundamentals of encoding and hashing in Python with simple examples
String encoding and hashing are two distinct operations that serve different purposes in computing and data processing. Encoding is a reversible process that transforms a string into a sequence of bytes, whereas hashing is an irreversible process that produces a fixed-length string of characters, which usually appears as a seemingly random sequence of characters.
In this post, we will introduce the basic concepts of encoding and hashing in Python with simple but practical examples, especially using base64 for encoding and SHA-256/SHAKE-256 for hashing. Hopefully, you will then have a better understanding of how encoding and hashing work in Python.
Unicode and UTF-8
In Python 3, a string by default is a Unicode string, and we need to use b'' to explicitly mark a string as a binary string.
my_string = "Lynn"
my_binary = b"Lynn"Alternatively, we can call the .encode() method of a string to encode the string using the specified encoding format, which is UTF-8 by default. UTF-8 is the most commonly used encoding format for Unicode characters.










