# cryptolu/meetinthefilter_cham_katan architecture

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

- Interactive diagram: https://gitdiagram.com/cryptolu/meetinthefilter_cham_katan
- Repository: https://github.com/cryptolu/meetinthefilter_cham_katan

## Overview

This repository is research code for meet-in-the-filter and differential-cryptanalysis experiments on CHAM and KATAN, plus trail data used by the attacks. The principal workflow is to analyze or expand differential trails, run cipher-specific experiments or attack code, and inspect resulting probabilities, trail matches, or key candidates. The graph separates the two cipher toolsets and the shared trail corpus. Some capabilities are identified from filenames and the README rather than sampled implementation, so uncertain wiring is omitted.

Main entry points: [`cham/trails_forward.py`](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/trails_forward.py) (Forward trail analysis), [`cham/gain/mifattack.cpp`](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/gain/mifattack.cpp) (MiF attack), [`katan/katan32-mif.cpp`](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan32-mif.cpp) (MiF attack), [`cham/cham-exp.cpp`](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/cham-exp.cpp) (Success experiments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cham["CHAM experiments"]
  node_cham_core["CHAM implementation<br/>[cham.py]"]
  node_cham_exp["Success experiments<br/>[cham-exp.cpp]"]
  node_cham_gain["MiF attack<br/>[mifattack.cpp]"]
  node_cham_recursive["Key recovery<br/>[recursive.cpp]"]
  node_cham_arx["ARX analysis<br/>[arx.py]"]
  node_cham_forward["Forward trail analysis<br/>[trails_forward.py]"]
  node_cham_backward["Backward trail analysis"]
end

subgraph group_katan["KATAN experiments"]
  node_katan_core["KATAN cipher<br/>[katan.py]"]
  node_katan_mif["MiF attack<br/>[katan32-mif.cpp]"]
  node_katan_expand["Trail expansion<br/>[katan32-expand.cpp]"]
  node_katan_smt32["32-bit SMT model<br/>[katan32.py]"]
  node_katan_smt48["48-bit SMT model<br/>[katan48.py]"]
  node_katan_smt64["64-bit SMT model<br/>[katan64.py]"]
end

subgraph group_traildata["Differential trails"]
  node_cham_trail["CHAM trail"]
  node_katan32_trail["KATAN32 trail"]
  node_katan48_trail["KATAN48 trail"]
  node_katan64_trail["KATAN64 trail"]
end

node_researcher(("Researcher"))
node_results["Experiment results"]

node_researcher -->|"runs experiments"| node_cham_exp
node_researcher -->|"runs attack"| node_cham_gain
node_researcher -->|"analyzes trails"| node_cham_forward
node_cham_exp -->|"uses cipher"| node_cham_core
node_cham_exp -->|"reports success rate"| node_results
node_cham_gain -->|"recovers key"| node_cham_recursive
node_cham_gain -->|"reports candidates"| node_results
node_researcher -->|"analyzes trails"| node_cham_backward
node_cham_forward -->|"expands differences"| node_cham_core
node_cham_forward -->|"counts ARX differences"| node_cham_arx
node_cham_forward -->|"reports probabilities"| node_results
node_researcher -->|"runs attack"| node_katan_mif
node_katan_mif -->|"uses cipher schedule"| node_katan_core
node_katan_mif -->|"reports trail matches"| node_results
node_researcher -->|"expands trails"| node_katan_expand
node_katan_expand -->|"reports statistics"| node_results
node_researcher -->|"models characteristics"| node_katan_smt32
node_researcher -->|"models characteristics"| node_katan_smt48
node_researcher -->|"models characteristics"| node_katan_smt64
node_cham_trail -.->|"attack trail input"| node_cham_gain
node_katan32_trail -.->|"attack trail input"| node_katan_mif

click node_cham_core "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/cham.py"
click node_cham_exp "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/cham-exp.cpp"
click node_cham_gain "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/gain/mifattack.cpp"
click node_cham_recursive "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/gain/recursive.cpp"
click node_cham_arx "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/arx.py"
click node_cham_forward "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/trails_forward.py"
click node_cham_backward "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/pattern_backwards.py"
click node_katan_core "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan.py"
click node_katan_mif "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan32-mif.cpp"
click node_katan_expand "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan32-expand.cpp"
click node_katan_smt32 "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/cryptosmt/katan32.py"
click node_katan_smt48 "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/cryptosmt/katan48.py"
click node_katan_smt64 "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/cryptosmt/katan64.py"
click node_cham_trail "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/cham/cham64-40r-trail.txt"
click node_katan32_trail "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/katan/katan32-74r-offset33-trails.txt"
click node_katan48_trail "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/katan/katan48-87r-offset34-trails.txt"
click node_katan64_trail "https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/katan/katan64-79r-offset33-trails.txt"

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_cham_core,node_cham_exp,node_cham_gain,node_cham_recursive,node_cham_arx,node_cham_forward,node_cham_backward toneBlue
class node_katan_core,node_katan_mif,node_katan_expand,node_katan_smt32,node_katan_smt48,node_katan_smt64 toneAmber
class node_cham_trail,node_katan32_trail,node_katan48_trail,node_katan64_trail toneMint
class node_researcher,node_results toneIndigo
```

## Components

### CHAM experiments

- [CHAM implementation](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/cham.py): `cham/cham.py`
- [Success experiments](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/cham-exp.cpp): `cham/cham-exp.cpp`
- [MiF attack](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/gain/mifattack.cpp): `cham/gain/mifattack.cpp`
- [Key recovery](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/gain/recursive.cpp): `cham/gain/recursive.cpp`
- [ARX analysis](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/arx.py): `cham/arx.py`
- [Forward trail analysis](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/trails_forward.py): `cham/trails_forward.py`
- [Backward trail analysis](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/cham/pattern_backwards.py): `cham/pattern_backwards.py`

### KATAN experiments

- [KATAN cipher](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan.py): `katan/katan.py`
- [MiF attack](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan32-mif.cpp): `katan/katan32-mif.cpp`
- [Trail expansion](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/katan32-expand.cpp): `katan/katan32-expand.cpp`
- [32-bit SMT model](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/cryptosmt/katan32.py): `katan/cryptosmt/katan32.py`
- [48-bit SMT model](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/cryptosmt/katan48.py): `katan/cryptosmt/katan48.py`
- [64-bit SMT model](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/katan/cryptosmt/katan64.py): `katan/cryptosmt/katan64.py`

### Differential trails

- [CHAM trail](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/cham/cham64-40r-trail.txt): `trails/cham/cham64-40r-trail.txt`
- [KATAN32 trail](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/katan/katan32-74r-offset33-trails.txt): `trails/katan/katan32-74r-offset33-trails.txt`
- [KATAN48 trail](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/katan/katan48-87r-offset34-trails.txt): `trails/katan/katan48-87r-offset34-trails.txt`
- [KATAN64 trail](https://github.com/cryptolu/meetinthefilter_cham_katan/blob/main/trails/katan/katan64-79r-offset33-trails.txt): `trails/katan/katan64-79r-offset33-trails.txt`

### Other components

- **Researcher**
- **Experiment results**

## Connections

- Researcher → Success experiments: runs experiments
- Researcher → MiF attack: runs attack
- Researcher → Forward trail analysis: analyzes trails
- Success experiments → CHAM implementation: uses cipher
- Success experiments → Experiment results: reports success rate
- MiF attack → Key recovery: recovers key
- MiF attack → Experiment results: reports candidates
- Researcher → Backward trail analysis: analyzes trails
- Forward trail analysis → CHAM implementation: expands differences
- Forward trail analysis → ARX analysis: counts ARX differences
- Forward trail analysis → Experiment results: reports probabilities
- Researcher → MiF attack: runs attack
- MiF attack → KATAN cipher: uses cipher schedule
- MiF attack → Experiment results: reports trail matches
- Researcher → Trail expansion: expands trails
- Trail expansion → Experiment results: reports statistics
- Researcher → 32-bit SMT model: models characteristics
- Researcher → 48-bit SMT model: models characteristics
- Researcher → 64-bit SMT model: models characteristics
- CHAM trail → MiF attack: attack trail input
- KATAN32 trail → MiF attack: attack trail input
