Encoding and Decoding Base64 Strings in Python

0
9K

The Base64 encoding is used to convert bytes that have binary or text data into ASCII characters. Encoding prevents the data from getting corrupted when it is transferred or processed through a text-only system. In this article, we will discuss about Base64 encoding and decoding and its uses to encode and decode binary and text data. Each Base64 character represents 6 bits of data. it is also important to note that it is not meant for encryption for obvious reasons.

 

import base64
  
sample_string = "Hello world!"
sample_string_bytes = sample_string.encode("ascii")
  
base64_bytes = base64.b64encode(sample_string_bytes)
base64_string = base64_bytes.decode("ascii")
  
print(base64_string)
Pesquisar
Categorias
Leia Mais
Business
What Challenges Do Creators Face?
The Creator Economy has opened up countless opportunities for individuals to share their...
Por Dacey Rankins 2025-02-24 16:02:51 0 5K
Cultures and Groups
Understanding Cultures: Diversity, Identity, and the Tapestry of Humanity
Culture is the essence of what makes a group of people unique. It encompasses the shared beliefs,...
Por Dacey Rankins 2024-11-07 16:38:01 0 8K
Astronomy
Exploring the Universe: An Introduction to Astronomy
Astronomy, the study of celestial bodies such as stars, planets, comets, and galaxies, as well as...
Por Dacey Rankins 2024-12-11 14:57:14 0 5K
Научная фантастика и фэнтези
Властелин колец: Две крепости. The Lord of the Rings: The Two Towers. (2002)
Братство распалось, но Кольцо Всевластья должно быть уничтожено. Фродо и Сэм вынуждены довериться...
Por Nikolai Pokryshkin 2022-11-10 10:38:15 0 28K
Stories
Gladiator. (2000)
A former Roman General sets out to exact vengeance against the corrupt emperor who murdered his...
Por Leonard Pokrovski 2022-11-29 20:39:00 0 16K
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov