Files
ChaosCrypt/chaoscrypt/legacy/README.md
T
dvs 2529edac1d v2.1.6: Restructure as a distributable library
Restructure ChaosCrypt from a single-file script into a complete,
installable Python package with three interfaces: a typed Python API, an
argument-driven CLI, and a bilingual interactive TUI.

The algorithm itself is unchanged. Ciphertexts and key files remain fully
interoperable with the original implementation in both directions, which is
enforced by dedicated tests rather than merely documented.

Added
- Library API: ChaosCrypt facade plus ChaosCryptCore for the raw algorithm
- Unified error hierarchy: 16 named types, all ChaosCryptError subclasses,
  rendering as ChaosCrypt_ERR_<Detail>_<Code>
- CLI: keygen, encrypt, decrypt, file, info, chpwd, tui, with --json output,
  stdin/stdout piping, and three password sources per secret
- Bilingual TUI: English default, runtime switch to Chinese, getpass password
  entry with a non-TTY fallback that keeps it scriptable
- Binary and file support: encrypt_bytes/decrypt_bytes and
  encrypt_file/decrypt_file
- Key management: change_key_password rewraps without altering key material;
  export_key_text/load_from_text move a key without touching disk
- Documentation: SECURITY.md with the full design and threat analysis, plus
  docs/ covering the API, CLI, architecture and build process
- Test suite: 92 tests across round-trips, binary safety, key management,
  error types, CLI, TUI, i18n and legacy interoperability
- Packaging: pyproject.toml, setup.py compatibility shim, MANIFEST.in,
  py.typed, examples, MIT licence

Fixed
- Conflicting --pwd option between the -p and -P groups prevented the CLI
  from starting at all
- Wrong key file password reported as file corruption (E002); structural
  validation now distinguishes it from a damaged file (E003)
- export_key_text produced key material without loading it into the instance
- Non-hexadecimal input was accepted as ciphertext and silently decrypted
  into garbage, making corruption indistinguishable from success; malformed
  input now raises E010 before any processing
- TUI failed under piped input because getpass requires a TTY
- TUI kept reading the default key file name after generating a new one

Changed
- Source tree reorganised: the package lives at chaoscrypt/, with tests,
  examples and legacy alongside it; documentation and build artefacts at the
  repository root
- Code comments unified in English; public docstrings document parameters,
  return values and raised exceptions
- English is now the default UI language
- ChaosCryptChat removed from the repository
- Attribution updated to Dvs (DvsXT); project URLs point to Gitea
2026-09-27 17:03:05 +08:00

58 lines
2.4 KiB
Markdown

# `legacy/` — The original single-file implementation
This directory preserves the **original single-file script** for three
purposes:
1. **Interoperability testing.** `tests/test_legacy_interop.py` loads
`chaoscrypt_legacy.py` and proves that data moves freely between the two
implementations in both directions.
2. **Historical reference.** The original form makes it easy to compare
behaviour before and after the restructure.
3. **Teaching.** A single file with no packaging concerns is often the clearer
way to read an algorithm end to end.
## Contents
| File | Description |
|---|---|
| `chaoscrypt_legacy.py` | The original `chaoscrypt.py`, **unmodified** |
| `encryption.key` | Sample key file used by the original script (test data only) |
## Important
- **Do not use these scripts.** New code should use the `chaoscrypt` package.
- This directory is **not** included in the wheel. It ships in the source
distribution only, for the tests above.
- The two implementations are **bit-for-bit equivalent** and share an
identical key file format, so key files and ciphertexts are freely
interchangeable between them.
## Verifying interoperability
```bash
# From the repository root
python -m pytest chaoscrypt/tests/test_legacy_interop.py -v
```
## Limitations of the original script
The original implementation worked, but its structure made it unsuitable as a
library. The restructure addressed the following:
1. **Algorithm and presentation were coupled.** `print` and `input` calls were
interleaved with the cryptographic logic, so the module could not be
imported and used programmatically.
2. **Failures returned strings rather than raising.** A failed decryption
returned a sentinel string such as `"Decryption failed"`, which callers had
to compare against a literal. Real exceptions make failure impossible to
overlook.
3. **Key loading state could become inconsistent.** A wrong key file password
printed a message but did not always leave the object in a well-defined
state.
4. **No command line interface.** Every operation required an interactive
session, so the script could not be used in automation.
5. **No binary or file-level API.** Only text could be encrypted directly.
6. **No unified error type.** Each failure path reported itself differently.
7. **Non-hexadecimal input was accepted silently.** A corrupt ciphertext would
decrypt into garbage and be indistinguishable from success.