Skip to content

Base64 Tool

CarterPerez-dev edited this page Feb 11, 2026 · 1 revision

Base64 Tool

Multi-format encoding/decoding CLI with recursive layer peeling for security analysis.

Overview

A Python CLI tool that handles Base64, Base64URL, Base32, hex, and URL encoding with automatic format detection and recursive multi-layer decoding. The standout feature is layer peeling β€” the same technique used to analyze obfuscated malware payloads and WAF bypass attempts.

Status: Complete | Difficulty: Beginner

Tech Stack

Technology Version Purpose
Python 3.14+ Modern syntax, native type hints
Typer - CLI framework
Rich - Terminal formatting

Features

Core Functionality

  • Encode/decode across 5 formats (Base64, Base64URL, Base32, Hex, URL)
  • Automatic format detection with confidence scoring
  • Recursive layer peeling (decodes stacked encodings)
  • Chain encoding (apply multiple encodings in sequence)
  • Pipe/stdin support

Security Relevance

  • Analyze obfuscated malware payloads (e.g., DARKGATE multi-layer encoding)
  • Decode WAF bypass attempts
  • Inspect JWT tokens, certificates, and hex dumps
  • Understand why encoding is not encryption

Architecture

User Command
    ↓
cli.py (Typer commands: encode, decode, detect, peel, chain)
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  encoders.py β”‚  detector.py β”‚   peeler.py  β”‚
β”‚  Pure encode β”‚  Format      β”‚  Recursive   β”‚
β”‚  /decode +   β”‚  detection + β”‚  multi-layer β”‚
β”‚  registry    β”‚  confidence  β”‚  decoding    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↓
formatter.py (Rich terminal output)

Quick Start

cd PROJECTS/beginner/base64-tool

# Install dependencies
uv sync

# Encode/decode
uv run b64tool encode "Hello World"
uv run b64tool decode "SGVsbG8gV29ybGQ="

# Auto-detect format
uv run b64tool detect "SGVsbG8gV29ybGQ="

# Multi-layer peeling
uv run b64tool chain "alert('xss')" --steps base64,hex
uv run b64tool peel "5957786c636e516f4a33687a63796370"

# Pipe support
echo "SGVsbG8=" | uv run b64tool decode

Project Structure

base64-tool/
β”œβ”€β”€ src/base64_tool/
β”‚   β”œβ”€β”€ cli.py          # Typer commands
β”‚   β”œβ”€β”€ constants.py    # Enums, thresholds, character sets
β”‚   β”œβ”€β”€ encoders.py     # Pure encode/decode functions + registry
β”‚   β”œβ”€β”€ detector.py     # Format detection with confidence scoring
β”‚   β”œβ”€β”€ peeler.py       # Recursive multi-layer decoding
β”‚   β”œβ”€β”€ formatter.py    # Rich terminal output
β”‚   └── utils.py        # Input resolution, text helpers
β”œβ”€β”€ tests/              # 78 tests across all modules
β”œβ”€β”€ pyproject.toml
└── Justfile

Development

# Run tests
uv run pytest tests/ -v

# Linting
uv run ruff check .

# Format
uv run ruff format .

Source Code

View on GitHub

Clone this wiki locally