# amanthink/xor_cipher architecture

> Architecture diagram of the GitHub repository amanthink/xor_cipher, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amanthink/xor_cipher
- Repository: https://github.com/amanthink/xor_cipher

## Overview

This is a single-file C++ command-line toolkit for CTF cipher analysis. The user supplies hex data and selects an attack, transform, ChaCha20 operation, or chained pipeline; the selected mode processes the bytes and prints results. Repeating-key XOR cracking estimates a key length before solving byte positions, while chain mode applies operations in order. All implementation paths below are main.cpp. The excerpts omit some handlers and helper bodies, so those links rely on README-described behavior; uncertain internal wiring is left out.

Main entry points: [`main.cpp`](https://github.com/amanthink/xor_cipher/blob/main/main.cpp) (Mode dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and encoding"]
  node_dispatch["Mode dispatch<br/>[main.cpp]"]
  node_hex["Hex conversion<br/>[main.cpp]"]
  node_tohex["ASCII to hex<br/>[main.cpp]"]
end

subgraph group_analysis["Cipher analysis"]
  node_single["Single-byte XOR<br/>[main.cpp]"]
  node_scoring["English scoring<br/>[main.cpp]"]
  node_multi["Repeating-key crack<br/>[main.cpp]"]
  node_keysize["Key-size estimate<br/>[main.cpp]"]
end

subgraph group_operations["Transforms and ciphers"]
  node_nibble["Nibble swap<br/>[main.cpp]"]
  node_rotation["Bit rotations<br/>[main.cpp]"]
  node_chacha_handler["ChaCha20 mode<br/>[main.cpp]"]
  node_chacha_crypt["Keystream XOR<br/>[main.cpp]"]
  node_chacha_block["ChaCha20 block<br/>[main.cpp]"]
  node_chain["Chain mode<br/>[main.cpp]"]
  node_chain_xor["Fixed-byte XOR<br/>[main.cpp]"]
end

node_user(("CLI user"))

node_user -->|"selects mode"| node_dispatch
node_dispatch -->|"decodes input"| node_hex
node_dispatch -->|"converts string"| node_tohex
node_dispatch -->|"dispatches"| node_single
node_dispatch -->|"dispatches"| node_multi
node_dispatch -->|"dispatches"| node_nibble
node_dispatch -->|"dispatches"| node_rotation
node_dispatch -->|"dispatches"| node_chacha_handler
node_dispatch -->|"dispatches"| node_chain
node_single -->|"scores candidates"| node_scoring
node_multi -->|"estimates key size"| node_keysize
node_multi -->|"cracks key blocks"| node_single
node_rotation -->|"scores candidates"| node_scoring
node_chacha_handler -->|"parses key and nonce"| node_hex
node_chacha_handler -->|"encrypts or decrypts"| node_chacha_crypt
node_chacha_crypt -->|"generates blocks"| node_chacha_block
node_chain -->|"applies XOR"| node_chain_xor
node_chain -->|"applies nibble swap"| node_nibble
node_chain -->|"applies rotations"| node_rotation

click node_dispatch "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_hex "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_tohex "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_single "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_scoring "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_multi "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_keysize "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_nibble "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_rotation "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_chacha_handler "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_chacha_crypt "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_chacha_block "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_chain "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"
click node_chain_xor "https://github.com/amanthink/xor_cipher/blob/main/main.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dispatch,node_hex,node_tohex,node_user toneBlue
class node_single,node_scoring,node_multi,node_keysize toneAmber
class node_nibble,node_rotation,node_chacha_handler,node_chacha_crypt,node_chacha_block,node_chain,node_chain_xor toneMint
```

## Components

### CLI and encoding

- [Mode dispatch](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Hex conversion](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [ASCII to hex](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`

### Cipher analysis

- [Single-byte XOR](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [English scoring](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Repeating-key crack](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Key-size estimate](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`

### Transforms and ciphers

- [Nibble swap](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Bit rotations](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [ChaCha20 mode](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Keystream XOR](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [ChaCha20 block](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Chain mode](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`
- [Fixed-byte XOR](https://github.com/amanthink/xor_cipher/blob/main/main.cpp): `main.cpp`

### Other components

- **CLI user**

## Connections

- CLI user → Mode dispatch: selects mode
- Mode dispatch → Hex conversion: decodes input
- Mode dispatch → ASCII to hex: converts string
- Mode dispatch → Single-byte XOR: dispatches
- Mode dispatch → Repeating-key crack: dispatches
- Mode dispatch → Nibble swap: dispatches
- Mode dispatch → Bit rotations: dispatches
- Mode dispatch → ChaCha20 mode: dispatches
- Mode dispatch → Chain mode: dispatches
- Single-byte XOR → English scoring: scores candidates
- Repeating-key crack → Key-size estimate: estimates key size
- Repeating-key crack → Single-byte XOR: cracks key blocks
- Bit rotations → English scoring: scores candidates
- ChaCha20 mode → Hex conversion: parses key and nonce
- ChaCha20 mode → Keystream XOR: encrypts or decrypts
- Keystream XOR → ChaCha20 block: generates blocks
- Chain mode → Fixed-byte XOR: applies XOR
- Chain mode → Nibble swap: applies nibble swap
- Chain mode → Bit rotations: applies rotations
