Base64 Encode/Decode
Encode and decode strings using Base64.
Code
Python
import base64
text = "Hello, World!"
encoded = base64.b64encode(text.encode()).decode()
print("Encoded:", encoded)
decoded = base64.b64decode(encoded).decode()
print("Decoded:", decoded)Line-by-line explanation
- 1.Import the base64 module.
- 2.Encode string to bytes, then base64 encode, then decode to string.
- 3.Use b64decode to reverse, then decode bytes to string.
Expected output
Encoded: SGVsbG8sIFdvcmxkIQ== Decoded: Hello, World!