base64
base64 module สำหรับ encoding binary data เป็น text และ decoding text กลับเป็น binary
Base64 คืออะไร
Section titled “Base64 คืออะไร”print("Base64 Encoding:")print("=" * 50)
print("""Base64 คือ: - วิธี encode binary data เป็น ASCII text - ใช้ 64 characters: A-Z, a-z, 0-9, +, / - Padding ด้วย = ถ้าไม่หารลงตัว
ทำไมต้องใช้: - ส่ง binary ผ่าน text-only protocols (email, JSON) - Embed binary ใน HTML/CSS/JavaScript - Store binary ใน text databases - JWT tokens
ข้อเสีย: - ขนาดเพิ่มขึ้น ~33% (4 chars = 3 bytes) - ไม่ใช่ encryption (decode ง่าย!)""")
# Size comparisonoriginal = b"Hello, World!"import base64encoded = base64.b64encode(original)print(f"Original: {len(original)} bytes")print(f"Encoded: {len(encoded)} chars (~{len(encoded)/len(original)*100:.0f}%)")เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google