cyclic-constraint-engine 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: cyclic-constraint-engine
3
+ Version: 0.1.0
4
+ Summary: Experimental cyclic alignment constraint-ledger prototype
5
+ Requires-Python: >=3.10
@@ -0,0 +1,12 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cyclic-constraint-engine"
7
+ version = "0.1.0"
8
+ description = "Experimental cyclic alignment constraint-ledger prototype"
9
+ requires-python = ">=3.10"
10
+
11
+ [tool.setuptools.packages.find]
12
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,111 @@
1
+ from .cipher_libraries import (
2
+ ALPHA_CIPHER_IDS,
3
+ DIGIT_SPECIAL,
4
+ KEYBOARD_CIPHER_LIBRARIES,
5
+ LETTER_PUNCTUATION,
6
+ NUMERIC_CIPHER_IDS,
7
+ SLOTS_PER_CIPHER,
8
+ SLOTS_PER_LIBRARY,
9
+ TOTAL_PAIR_SLOTS,
10
+ KeyboardCipherLibraries,
11
+ build_keyboard_cipher_libraries,
12
+ )
13
+ from .engine import (
14
+ SIX_BASE,
15
+ SIX_CYCLES,
16
+ SEVEN_BASE,
17
+ SEVEN_CYCLES,
18
+ TARGET_NUMBER_COUNT,
19
+ AlignmentSums,
20
+ CipherLibraries,
21
+ CompressionSums,
22
+ PairedPlacementSearchResult,
23
+ PairedRecoveryStats,
24
+ PlacementSearchResult,
25
+ ReportDatasetEvaluation,
26
+ ReportDifferentials,
27
+ ReportRecoveryStats,
28
+ SevenSlotReport,
29
+ SlotInconsistency,
30
+ SlotReport,
31
+ TraversalPlan,
32
+ accumulate_alignments,
33
+ analyze_paired_report,
34
+ build_cipher_libraries,
35
+ build_traversal_plan,
36
+ compress_sums,
37
+ decode_paired_report,
38
+ decode_text_file,
39
+ encode_text_file,
40
+ evaluate_paired_recovery,
41
+ evaluate_report_dataset,
42
+ evaluate_report_uniqueness,
43
+ moving_zero_changes,
44
+ multiplier_cycles,
45
+ ordered_alignment_report,
46
+ paired_alignment_report,
47
+ read_report_file,
48
+ rotations,
49
+ serialize_paired_report,
50
+ slot_averages,
51
+ solve_paired_report,
52
+ solve_paired_report_file,
53
+ solve_stream_report,
54
+ sums_payload,
55
+ target_relative_zero,
56
+ )
57
+
58
+ __all__ = [
59
+ "ALPHA_CIPHER_IDS",
60
+ "DIGIT_SPECIAL",
61
+ "KEYBOARD_CIPHER_LIBRARIES",
62
+ "LETTER_PUNCTUATION",
63
+ "NUMERIC_CIPHER_IDS",
64
+ "SLOTS_PER_CIPHER",
65
+ "SLOTS_PER_LIBRARY",
66
+ "TOTAL_PAIR_SLOTS",
67
+ "KeyboardCipherLibraries",
68
+ "build_keyboard_cipher_libraries",
69
+ "SIX_BASE",
70
+ "SIX_CYCLES",
71
+ "SEVEN_BASE",
72
+ "SEVEN_CYCLES",
73
+ "TARGET_NUMBER_COUNT",
74
+ "AlignmentSums",
75
+ "CipherLibraries",
76
+ "CompressionSums",
77
+ "PairedPlacementSearchResult",
78
+ "PairedRecoveryStats",
79
+ "PlacementSearchResult",
80
+ "ReportDatasetEvaluation",
81
+ "ReportDifferentials",
82
+ "ReportRecoveryStats",
83
+ "SevenSlotReport",
84
+ "SlotInconsistency",
85
+ "SlotReport",
86
+ "TraversalPlan",
87
+ "accumulate_alignments",
88
+ "analyze_paired_report",
89
+ "build_cipher_libraries",
90
+ "build_traversal_plan",
91
+ "compress_sums",
92
+ "decode_paired_report",
93
+ "decode_text_file",
94
+ "encode_text_file",
95
+ "evaluate_paired_recovery",
96
+ "evaluate_report_dataset",
97
+ "evaluate_report_uniqueness",
98
+ "moving_zero_changes",
99
+ "multiplier_cycles",
100
+ "ordered_alignment_report",
101
+ "paired_alignment_report",
102
+ "read_report_file",
103
+ "rotations",
104
+ "serialize_paired_report",
105
+ "slot_averages",
106
+ "solve_paired_report",
107
+ "solve_paired_report_file",
108
+ "solve_stream_report",
109
+ "sums_payload",
110
+ "target_relative_zero",
111
+ ]
@@ -0,0 +1,120 @@
1
+ """Two distinct six-group keyboard cipher libraries.
2
+
3
+ Cipher IDs 1-6 cover letters and punctuation. Cipher IDs a-f cover digits,
4
+ remaining special characters, and common text controls. Each symbol maps to a
5
+ (cipher ID, position within that ID's ordered string) pair.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass
11
+ from string import ascii_letters, digits, punctuation
12
+ from typing import Dict, Mapping, Tuple, Union
13
+
14
+ CipherId = Union[int, str]
15
+
16
+ LETTER_PUNCTUATION = ascii_letters + ".,!?:;'\"-()[]{}"
17
+ DIGIT_SPECIAL = digits + "@#$%^&*+=_/< >\\|~`".replace(" ", "") + " \t\n\r"
18
+ NUMERIC_CIPHER_IDS: Tuple[int, ...] = (1, 2, 3, 4, 5, 6)
19
+ ALPHA_CIPHER_IDS: Tuple[str, ...] = ("a", "b", "c", "d", "e", "f")
20
+ SLOTS_PER_CIPHER = 14
21
+ SLOTS_PER_LIBRARY = 6 * SLOTS_PER_CIPHER
22
+ TOTAL_PAIR_SLOTS = 2 * SLOTS_PER_LIBRARY
23
+
24
+
25
+ def _groups(chars: str, ids: Tuple[CipherId, ...]) -> Dict[CipherId, str]:
26
+ """Split an ordered character set into six stable, disjoint strings."""
27
+ if len(set(chars)) != len(chars):
28
+ raise ValueError("library character sequence contains duplicates")
29
+ return {
30
+ group_id: "".join(chars[index] for index in range(len(chars)) if index % 6 == group_index)
31
+ for group_index, group_id in enumerate(ids)
32
+ }
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class KeyboardCipherLibraries:
37
+ """Separate numeric-ID and letter-ID libraries with reversible positions."""
38
+
39
+ numeric_ciphers: Mapping[int, str]
40
+ alpha_ciphers: Mapping[str, str]
41
+
42
+ @property
43
+ def capacity(self) -> int:
44
+ """Return total pair-slot capacity across both independent libraries."""
45
+ return TOTAL_PAIR_SLOTS
46
+
47
+ @property
48
+ def library_capacities(self) -> Tuple[int, int]:
49
+ """Return numeric-library and letter-library slot capacities."""
50
+ return SLOTS_PER_LIBRARY, SLOTS_PER_LIBRARY
51
+
52
+ @property
53
+ def character_codes(self) -> Mapping[str, Tuple[CipherId, int]]:
54
+ codes: Dict[str, Tuple[CipherId, int]] = {}
55
+ for cipher_id, chars in self.numeric_ciphers.items():
56
+ for position, char in enumerate(chars):
57
+ codes[char] = (cipher_id, position)
58
+ for cipher_id, chars in self.alpha_ciphers.items():
59
+ for position, char in enumerate(chars):
60
+ if char in codes:
61
+ raise ValueError(f"character occurs in both libraries: {char!r}")
62
+ codes[char] = (cipher_id, position)
63
+ return codes
64
+
65
+ def validate(self) -> None:
66
+ if tuple(self.numeric_ciphers) != NUMERIC_CIPHER_IDS:
67
+ raise ValueError("numeric cipher IDs must be ordered 1 through 6")
68
+ if tuple(self.alpha_ciphers) != ALPHA_CIPHER_IDS:
69
+ raise ValueError("letter cipher IDs must be ordered a through f")
70
+ codes = self.character_codes
71
+ for cipher_id in NUMERIC_CIPHER_IDS:
72
+ if not self.numeric_ciphers[cipher_id]:
73
+ raise ValueError(f"numeric cipher {cipher_id} is empty")
74
+ if len(self.numeric_ciphers[cipher_id]) > SLOTS_PER_CIPHER:
75
+ raise ValueError(f"numeric cipher {cipher_id} exceeds {SLOTS_PER_CIPHER} slots")
76
+ for cipher_id in ALPHA_CIPHER_IDS:
77
+ if not self.alpha_ciphers[cipher_id]:
78
+ raise ValueError(f"letter cipher {cipher_id} is empty")
79
+ if len(self.alpha_ciphers[cipher_id]) > SLOTS_PER_CIPHER:
80
+ raise ValueError(f"letter cipher {cipher_id} exceeds {SLOTS_PER_CIPHER} slots")
81
+ expected = set(LETTER_PUNCTUATION) | set(DIGIT_SPECIAL)
82
+ if set(codes) != expected:
83
+ missing, extra = expected - set(codes), set(codes) - expected
84
+ raise ValueError(f"keyboard coverage mismatch; missing={missing}, extra={extra}")
85
+
86
+ def encode(self, text: str) -> Tuple[Tuple[CipherId, ...], Tuple[int, ...]]:
87
+ """Encode text into parallel cipher IDs and within-cipher positions."""
88
+ codes = self.character_codes
89
+ try:
90
+ pairs = [codes[char] for char in text]
91
+ except KeyError as exc:
92
+ raise ValueError(f"character is outside the defined keyboard: {exc.args[0]!r}") from exc
93
+ return tuple(pair[0] for pair in pairs), tuple(pair[1] for pair in pairs)
94
+
95
+ def decode(self, cipher_ids: Tuple[CipherId, ...], positions: Tuple[int, ...]) -> str:
96
+ """Rebuild text from parallel group identifiers and group positions."""
97
+ if len(cipher_ids) != len(positions):
98
+ raise ValueError("cipher ID and position streams must have equal length")
99
+ reverse = {
100
+ (cipher_id, position): char
101
+ for char, (cipher_id, position) in self.character_codes.items()
102
+ }
103
+ try:
104
+ return "".join(reverse[(cipher_id, position)] for cipher_id, position in zip(cipher_ids, positions))
105
+ except KeyError as exc:
106
+ raise ValueError(f"unknown cipher/position pair: {exc.args[0]!r}") from exc
107
+
108
+
109
+ def build_keyboard_cipher_libraries() -> KeyboardCipherLibraries:
110
+ """Return fixed 1-6 letter/punctuation and a-f digit/special libraries."""
111
+ # The order is part of the format: changing it changes character positions.
112
+ result = KeyboardCipherLibraries(
113
+ numeric_ciphers=_groups(LETTER_PUNCTUATION, NUMERIC_CIPHER_IDS),
114
+ alpha_ciphers=_groups(DIGIT_SPECIAL, ALPHA_CIPHER_IDS),
115
+ )
116
+ result.validate()
117
+ return result
118
+
119
+
120
+ KEYBOARD_CIPHER_LIBRARIES = build_keyboard_cipher_libraries()