Metadata-Version: 2.5
Name: imsherlock
Version: 0.1.0
Summary: Offline-first cipher, hash and encoding analysis orchestrator with replayable evidence-chain reports
Project-URL: Repository, https://github.com/zahT3/imsherlock
Project-URL: Changelog, https://github.com/zahT3/imsherlock/blob/main/CHANGELOG.md
Author: ImsherLOCK maintainers
License: Apache-2.0
License-File: LICENSE
Keywords: cipher,cryptography,ctf,forensics,hash-identification,offline-first
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security :: Cryptography
Requires-Python: >=3.11
Requires-Dist: jsonschema>=4.21
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# ImsherLOCK

English | [中文](#中文)

> Ciphertext, hash, encoding or puzzle in — a typed, evidence-chain report out.
> Offline-first. Refuses unauthorized attacks by default. Orchestrates mature local
> tools instead of reimplementing hashcat / CyberChef / Ciphey.

**Legal use.** Use ImsherLOCK only on data you own or are explicitly authorized to audit,
on CTF samples, or for teaching and research. It does not provide online attacks,
credential stuffing, authentication bypass, or cracking of third-party accounts.
The authorization classifier only inspects `--request` free text and natural-language
positional arguments; encoded or hash-shaped ciphertext is treated as data. A refusal
happens only when the classifier fires (exit code `2`).

**Status (2026-11-16).** MVP implemented as version `0.1.0`: five subcommands, 35/35
pre-registered fixtures, and reports that `verify` can replay. `0.1.0` is **not published
yet** — `pip install imsherlock` currently installs the `0.0.1` name-reservation
placeholder. A maintainer runs the release steps in [docs/release.md](docs/release.md);
this repository never publishes automatically.

## What it is / is not

| It is | It is not |
|---|---|
| Type identification and hypothesis ranking (encoding / hash / JWT / classical / randomness) | A universal decryptor |
| Bounded, reproducible transform-chain search with five-gate decisions | A GPU / distributed brute-force engine |
| Reports with evidence chains that can be replayed or rejected | A "one-click pwn" attack platform |
| A CLI and Agent Skill (Claude / Codex / DeepSeek) | An online attack or query service |
| Optional adapters and cross-source arbitration for external tools | A replacement for Ciphey / CyberChef / hashcat |

**Non-goals in this release:** online attacks, credential stuffing, authentication
bypass, hash cracking, GPU/distributed cracking, MCP/Web UI, and automatic download or
bundling of external tools. hashcat is wired for real `--identify` only (never cracking);
Ciphey / CyberChef / haiti remain probe + subprocess skeletons with unverified real
output. See [adapter goldens](docs/research/06-adapter-goldens.md).

## Install

```bash
git clone https://github.com/zahT3/imsherlock && cd imsherlock
uv tool install .            # or: pipx install .
imslock --version            # imsherlock 0.1.0

# development
uv sync --extra dev
uv run imslock --help
```

Python ≥ 3.11. The only runtime dependency is `jsonschema` (MIT); no network calls, no
telemetry. External tools (Ciphey / CyberChef / haiti / hashcat) are **not bundled** and
missing ones degrade to a warning. `--online` is a reserved flag and a **no-op** in this
release: no network client is loaded, adapters are not allowed online, and the report only
records `privacy.online_requested` while `online=false`. Adapters do **environment
isolation** (argv arrays, env allowlist, proxy stripping, timeouts, rlimits), not a
syscall-level network sandbox; `network_used` is a declared tri-state
(`true` / `false` / `null`, where `null` means "cannot prove").

## Five commands

```bash
# 1. Full analysis: identification + bounded search + five-gate decision + JSON report
imslock analyze 'SGVsbG8=' --json
imslock analyze --input-file sample.bin --show-input --output report.json --format md

# 2. Identification only: no transform search, no solving, no adapter probing
imslock identify '5f4dcc3b5aa765d61d8327deb882cf99'              # hash family -> 1
imslock identify 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.sig'      # unique JWT   -> 0

# 3. Replay the evidence chain; reports the first inconsistent step_id
imslock verify report.json --input-file sample.bin
imslock verify report-with-input.json

# 4. Environment self-check: version, KB, schema, real adapter probes
imslock doctor --json

# 5. Authorization rules, data retention, adapter safety properties
imslock explain-policy --lang en
imslock explain-policy --request 'crack this password' --json
```

Exit codes: `0` `analyze` solved, or `identify` found one definitive structure
(JWT/PEM/PGP/SSH public key/container magic, `hypotheses[].definitive=true`); `1`
hypotheses/undetermined, hash-family candidates, multiple same-shape candidates,
classical suspicion or noise; `2` refused; `3` usage error (including `--crack`); `4`
internal error. `definitive` is identification metadata and does not upgrade a conclusion
to `solved`.

**Privacy and verify.** Default reports keep only an input fingerprint and preview, never
`input.text` / `input.raw_b64`. `verify` therefore needs `--input-file` (original bytes;
short text may use `--input`) or a report produced with `--show-input`. Without input it
returns `reason=input_not_retained` and exits `1`; `imslock verify --help` has copyable
examples.

## Report shape

```json
{
  "schema_version": "1.1.0",
  "report_id": "6290d78cb69effc7e62b0ffb61bd6ff642feac657345d41cc8bbd01deac3c501",
  "calibration": {
    "version": "2026.11.16",
    "method": "histogram_binning",
    "applied": true,
    "fit_split": "fit",
    "source": "knowledge/data/calibration.json"
  },
  "conclusions": {
    "status": "solved",
    "label": "encoding:base64",
    "solved_value": "Hello",
    "reason_code": "solved",
    "incomplete": false,
    "evidence_step_id": "n1"
  },
  "steps": [
    {
      "step_id": "n1",
      "transform_id": "encoding.base64",
      "params": {"variant": "std"},
      "input_sha256": "50e7ab41c843a6b034d6d1d3bff2bbd7ac3e693e857075f6a2035b39fca88588",
      "output_sha256": "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969",
      "preview": "Hello"
    }
  ],
  "arbitration": {
    "status": "single_source",
    "winner": {"label": "encoding:base64", "source": "builtin"},
    "conflict": false
  },
  "privacy": {"show_input": false, "online": false}
}
```

The JSON Schema ([schema/report.schema.json](schema/report.schema.json)) is authoritative;
Markdown is rendered from the same model, and consumers must ignore unknown fields.
`hypotheses[].confidence` is raw and drives ranking, gates and the solved threshold;
`hypotheses[].confidence_reported` is post-hoc calibrated for humans only, and never
affects decisions (`report.confidence_semantics` says the same thing).

## Evaluation gates

| Gate | Measured | Verdict |
|---|---|---|
| G1 fixtures | 35/35 (verify 35/35) | pass |
| G2 identification accuracy / top-3 | 0.9815 / 1.0000 (n=54) | pass |
| G3 calibration | runtime `confidence_reported` ECE 0.01808 / Brier 0.001164 (eval 220; raw control ECE 0.064908) | pass on runtime field; decisions still use raw |
| G4 false accepts | random bytes 0/1000; AEAD-shaped 0/100; letter noise with spaces 0/1000; random token strings 0/500 | pass |
| G5 refuse / allow / grey zone | 12/12, 12/12, 12/12 | pass |
| G6 replayability | 35/35 | pass |
| G7 determinism | 3/3 | pass |
| G8 performance | 1 KiB p95 281.6 ms, max 319.2 ms; measured budget 319 ms ≤ 30 s | pass |
| G9 solving ladder | encoding 8/8, monoalphabetic 9/9, blind Vigenère 0/5 | Vigenère missed |
| G10 privacy | no complete input in reports / logs / temp files | pass |

Full numbers, environment and known misses: [docs/research/05-baseline.md](docs/research/05-baseline.md)
and the Ciphey comparison in [docs/research/07-baseline-comparison.md](docs/research/07-baseline-comparison.md).

## Docs

- [Constitution / project rules](constitution.md)
- [Requirements](docs/specs/imsherlock/requirements.md) · [Capability specs](docs/specs/)
- [Implementation notes and known gaps](docs/implementation-notes.md)
- [Evaluation plan (pre-registered)](docs/evaluation.md) · [Baseline](docs/research/05-baseline.md) · [SC-011 Ciphey comparison](docs/research/07-baseline-comparison.md)
- [Adapter goldens (hashcat)](docs/research/06-adapter-goldens.md)
- [Architecture decisions ADR-0001–0007](docs/decisions/)
- [Dependencies and licenses](docs/dependencies.md) · [CHANGELOG](CHANGELOG.md) · [Release runbook](docs/release.md)
- [Naming and name reservations](docs/naming.md)

## Not affiliated

The name is a nod to the BBC *Sherlock* "I AM _ _ _ _ LOCKED" puzzle. This project is not
affiliated with the BBC, the *Sherlock* production, or the
`sherlock-project/sherlock` project. The name is replaceable: change the package name and
the docs once.

## License

Apache-2.0, see [LICENSE](LICENSE). GPL tools can only be optional adapters installed by
the user and isolated in a subprocess; they are not distributed here.

---

## 中文

> 给一段密文、哈希、编码串或谜题：**读特征 → 识别 → 有界求解 → 输出可复核的证据链报告**。
> 离线优先 · 默认拒绝未授权攻击 · 不重写 hashcat/CyberChef/Ciphey，只做编排与仲裁。

**合法用途**：仅限自有数据、明确授权的审计、CTF 竞赛与教学研究。本工具不提供在线攻击、
撞库、绕过认证或破解第三方账号的能力。**授权分类只针对 `--request` 自由文本和自然语言
位置参数**；编码/哈希形态的密文按数据处理，不做解码后的语义拦截（拒绝只发生在分类命中时，
退出码 2）。

**状态**：MVP 已实现，版本 `0.1.0`（2026-11-16 准备发布）。五个子命令可用，35 条预注册
fixtures 全部通过，报告可 `verify` 重放。**0.1.0 尚未发布**：`pip install imsherlock`
目前装到的是 `0.0.1` 占名占位包；发布动作由维护者按 [docs/release.md](docs/release.md)
手动执行，本仓库不自动发布。

### 安装

尚未发布 0.1.0；从源码安装（需要 Python ≥ 3.11）：

```bash
git clone https://github.com/zahT3/imsherlock && cd imsherlock

uv tool install .            # 或：pipx install .
imslock --version            # imsherlock 0.1.0

# 开发环境
uv sync --extra dev
uv run imslock --help
```

运行时只依赖 `jsonschema`（MIT）；不联网、无遥测。外部工具（Ciphey/CyberChef/haiti/
hashcat）**不打包**，缺失时只降级为 warning。`--online` 是保留参数、当前版本为 **no-op**：
不会加载任何网络客户端，也不允许适配器联网，报告只记录 `privacy.online_requested` 并保持
`online=false`。hashcat 已接入真实 `--identify`（仅识别、永不 crack）：装了 hashcat 的机器会
对哈希类输入多取一个第二意见，耗时约 0.5–1.4 s；未安装时 `doctor` 报 `unavailable`，核心能力
不变。适配器只做**环境隔离**（参数数组、环境变量白名单、代理剥离、超时与 rlimit），
**不保证 syscall 级断网**；`network_used` 是声明的 tri-state。

### 五个命令

```bash
imslock analyze 'SGVsbG8=' --json                     # 完整分析
imslock identify 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.sig'  # 只识别结构（唯一 JWT → 0）
imslock verify report.json --input-file sample.bin    # 重放证据链
imslock doctor --json                                 # 环境自检
imslock explain-policy --lang zh                      # 授权规则与数据留存
```

退出码：`0` `analyze` 已解出，或 `identify` 以唯一确定结构（JWT/PEM/PGP/SSH 公钥/容器
魔数，报告中 `hypotheses[].definitive=true`）；`1` hypotheses/undetermined、哈希族候选、
多个同形候选、古典嫌疑或噪声；`2` refused；`3` 用法错误（含 `--crack`）；`4` 内部错误。
`identify` 的 `definitive` 只是识别元数据，不把结论升级为 `solved`。

**默认隐私与 verify**：默认报告只含输入指纹与预览，不含 `input.text` / `input.raw_b64`。
因此 `verify` 必须用 `--input-file`（原始字节；短文本也可用 `--input`）重放，或先
`analyze --show-input` 生成内嵌 `input.raw_b64` 的报告。缺少输入时 `verify` 返回
`reason=input_not_retained` 并退出 1；`imslock verify --help` 给出可直接复制的示例。
报告字段示例见上文 [Report shape](#report-shape)；完整字段以
[schema/report.schema.json](schema/report.schema.json) 为准。

### 它是什么 / 不是什么

| 是 | 不是 |
|---|---|
| 类型识别与假设排序（编码 / 哈希 / JWT / 经典密码 / 随机性） | 万能解密器 |
| 有界、可复现的变换链搜索与五门判定 | GPU/分布式暴力破解引擎 |
| 带证据链、可重放、可拒绝的报告 | 「一键拿下」的攻击平台 |
| CLI + Agent Skill（可挂 Claude/Codex/DeepSeek） | 在线攻击/查询服务 |
| 外部工具的可选适配器与跨源仲裁 | Ciphey/CyberChef/hashcat 的替代实现 |

本版本**不做**：在线攻击、撞库、绕过认证、哈希破解、GPU/分布式爆破、MCP/Web UI、
自动下载或打包外部工具。Ciphey/CyberChef/haiti 仍是探测 + 子进程骨架，真实输出未验证；
hashcat 只做识别、不 crack。

### 评测门（摘要）

| 门 | 实测 | 结论 |
|---|---|---|
| G1 fixtures | 35/35（verify 35/35） | 通过 |
| G2 识别 accuracy / top-3 | 0.9815 / 1.0000（n=54） | 通过 |
| G3 校准 | 运行时 `confidence_reported` ECE 0.01808 / Brier 0.001164（eval 220；raw 对照 ECE 0.064908） | 运行时口径通过；判定仍用 raw |
| G4 误接受 | 随机字节 0/1000；AEAD 形 0/100；字母噪声 0/1000；随机 token 串 0/500 | 通过 |
| G5 拒绝/合法/灰区 | 12/12、12/12、12/12 | 通过 |
| G6 可重放 | 35/35 | 通过 |
| G7 确定性 | 3/3 | 通过 |
| G8 性能 | 1 KiB p95 281.6 ms、max 319.2 ms；预算 319 ms ≤ 30 s | 通过 |
| G9 求解阶梯 | 编码 8/8、单表 9/9、盲 Vigenère 0/5 | Vigenère 未达标 |
| G10 隐私 | 报告/日志/临时文件无完整输入 | 通过 |

完整数字、环境与未达标项见 [docs/research/05-baseline.md](docs/research/05-baseline.md)。

### 网络边界

默认离线、无网络客户端；`--online` 是 no-op（不加载客户端、不允许适配器联网，报告只记
`online_requested`）。适配器只做环境隔离，不保证 syscall 级断网；`network_used` 是**声明的
tri-state**（`true` / `false` / `null`），`null` 表示本地工具运行时无法证明其网络行为，
不是断网证明。需要强隔离请用容器/网络命名空间。

### 文档

- [项目铁律 constitution.md](constitution.md)
- [需求](docs/specs/imsherlock/requirements.md) · [能力规格](docs/specs/)
- [实现说明与已知缺口](docs/implementation-notes.md)
- [评测方案（预注册）](docs/evaluation.md) · [基线](docs/research/05-baseline.md) · [SC-011 Ciphey 对照](docs/research/07-baseline-comparison.md)
- [适配器 golden（hashcat）](docs/research/06-adapter-goldens.md)
- [架构决策 ADR-0001–0007](docs/decisions/)
- [依赖与许可证](docs/dependencies.md) · [变更记录](CHANGELOG.md) · [发布说明](docs/release.md)
- [命名与占名](docs/naming.md)

### 不隶属声明

本项目名致敬 BBC《Sherlock》"I AM _ _ _ _ LOCKED" 谜题，但与 BBC、Sherlock 剧组、
`sherlock-project/sherlock` 项目均无关联；项目名可替换，包名/文档改一处即可。

### 许可证

Apache-2.0（见 [LICENSE](LICENSE)）。GPL 工具只能作为用户自装、进程隔离的可选适配器，
不进入发行物。
