Base64 & Encoding Quick Reference
=================================

BASE64
  Alphabet: A-Z a-z 0-9 + / (padding: =)
  Encodes 3 bytes → 4 characters
  Decodes 4 characters → 3 bytes

  # Command line
  echo -n "text" | base64          Encode
  echo "dGV4dA==" | base64 -d     Decode (Linux)
  echo "dGV4dA==" | base64 -D     Decode (macOS)
  base64 file > encoded.txt       Encode file
  base64 -d encoded.txt > file    Decode file

  # Python
  import base64
  base64.b64encode(b"text")       → b"dGV4dA=="
  base64.b64decode(b"dGV4dA==")   → b"text"

  # URL-safe Base64
  base64.urlsafe_b64encode(data)  Uses - and _ instead of + and /
  base64.urlsafe_b64decode(data)

BASE32
  Alphabet: A-Z 2-7 (padding: =)
  echo -n "text" | base32
  base64.b32encode(b"text")
  base64.b32decode(b"ORSXG5A=")

HEX
  echo -n "text" | xxd -p         Encode to hex
  echo "74657874" | xxd -r -p     Decode from hex
  bytes.fromhex("74657874")       Python decode
  b"text".hex()                   Python encode

URL ENCODING
  # Python
  from urllib.parse import quote, unquote
  quote("hello world")            → "hello%20world"
  unquote("hello%20world")        → "hello world"

ROT13
  echo "text" | tr 'a-zA-Z' 'n-za-mN-ZA-M'
  import codecs; codecs.decode("grkg", "rot_13")

BINARY
  # Python
  bin(65)                          → "0b1000001"
  int("1000001", 2)               → 65
  ''.join(format(b, '08b') for b in data)   Bytes to binary

ASCII TABLE (key values)
  0x00  NULL       0x20  SPACE      0x30  '0'
  0x09  TAB        0x41  'A'        0x61  'a'
  0x0a  LF (\n)    0x5a  'Z'        0x7a  'z'
  0x0d  CR (\r)    0x7e  '~'        0x7f  DEL

CTF TIPS
  - Try "Magic" in CyberChef to auto-detect encoding
  - Flags often have multiple layers: Base64(Hex(XOR(flag)))
  - Look for patterns: "==" at end = base64, all hex chars = hex
  - base64 length is always multiple of 4
