From c022b12e630eaf77aa8be5380033e964fc095504 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:03:03 +0000 Subject: [PATCH 1/3] Initial plan From 434fd04dfe122671c339088828ff8bb333497188 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:10:15 +0000 Subject: [PATCH 2/3] Add Trithemius cipher codec Co-authored-by: dhondta <9108102+dhondta@users.noreply.github.com> Agent-Logs-Url: https://github.com/dhondta/python-codext/sessions/f1d18334-920c-498b-8516-13b37307b393 --- src/codext/crypto/__init__.py | 1 + src/codext/crypto/trithemius.py | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/codext/crypto/trithemius.py diff --git a/src/codext/crypto/__init__.py b/src/codext/crypto/__init__.py index 0854db2..a46bfe6 100644 --- a/src/codext/crypto/__init__.py +++ b/src/codext/crypto/__init__.py @@ -9,5 +9,6 @@ from .rot import * from .scytale import * from .shift import * +from .trithemius import * from .xor import * diff --git a/src/codext/crypto/trithemius.py b/src/codext/crypto/trithemius.py new file mode 100644 index 0000000..e465edb --- /dev/null +++ b/src/codext/crypto/trithemius.py @@ -0,0 +1,60 @@ +# -*- coding: UTF-8 -*- +"""Trithemius Cipher Codec - trithemius content encoding. + +The Trithemius cipher is a polyalphabetic encryption method invented by the German +abbot Johannes Trithemius. It applies a sequence of progressive Caesar shifts (0, 1, +2, ...) to each successive letter in the plaintext, leaving non-alphabetic characters +unchanged. It is equivalent to a Vigenère cipher with the key "ABCDEFGHIJKLMNOPQRSTUVWXYZ...". + +This codec: +- en/decodes strings from str to str +- en/decodes strings from bytes to bytes +- decodes file content to str (read) +- encodes file content from str to bytes (write) + +Reference: https://www.dcode.fr/trithemius-cipher +""" +from string import ascii_lowercase as LC, ascii_uppercase as UC + +from ..__common__ import * + + +__examples__ = { + 'enc(trithemius|trithemius-cipher)': {'this is a test': "tikv mx g ambd"}, + 'enc(trithemius)': { + '': "", + 'HELLO': "HFNOS", + '12345!@#$': "12345!@#$", + }, + 'enc-dec(trithemius)': ["Hello, World!", "@random"], +} +__guess__ = ["trithemius"] + + +def _trithemius(text, decode=False): + r, pos = "", 0 + for c in ensure_str(text): + if c in LC: + r += LC[(LC.index(c) + (-pos if decode else pos)) % 26] + pos += 1 + elif c in UC: + r += UC[(UC.index(c) + (-pos if decode else pos)) % 26] + pos += 1 + else: + r += c + return r + + +def trithemius_encode(text, errors="strict"): + r = _trithemius(ensure_str(text)) + return r, len(text) + + +def trithemius_decode(text, errors="strict"): + r = _trithemius(ensure_str(text), decode=True) + return r, len(text) + + +add("trithemius", trithemius_encode, trithemius_decode, + r"trithemius(?:[-_]cipher)?$", + entropy=lambda e: e, printables_rate=lambda pr: pr, transitive=True) From 4971b0a76867962724bf32a0e60c143fba2fc1d1 Mon Sep 17 00:00:00 2001 From: Alex <9108102+dhondta@users.noreply.github.com> Date: Mon, 23 Mar 2026 21:21:39 +0100 Subject: [PATCH 3/3] Fine-tuned trithemius --- src/codext/crypto/trithemius.py | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/codext/crypto/trithemius.py b/src/codext/crypto/trithemius.py index e465edb..c72e744 100644 --- a/src/codext/crypto/trithemius.py +++ b/src/codext/crypto/trithemius.py @@ -1,18 +1,11 @@ # -*- coding: UTF-8 -*- """Trithemius Cipher Codec - trithemius content encoding. -The Trithemius cipher is a polyalphabetic encryption method invented by the German -abbot Johannes Trithemius. It applies a sequence of progressive Caesar shifts (0, 1, -2, ...) to each successive letter in the plaintext, leaving non-alphabetic characters -unchanged. It is equivalent to a Vigenère cipher with the key "ABCDEFGHIJKLMNOPQRSTUVWXYZ...". - This codec: - en/decodes strings from str to str - en/decodes strings from bytes to bytes - decodes file content to str (read) - encodes file content from str to bytes (write) - -Reference: https://www.dcode.fr/trithemius-cipher """ from string import ascii_lowercase as LC, ascii_uppercase as UC @@ -21,12 +14,8 @@ __examples__ = { 'enc(trithemius|trithemius-cipher)': {'this is a test': "tikv mx g ambd"}, - 'enc(trithemius)': { - '': "", - 'HELLO': "HFNOS", - '12345!@#$': "12345!@#$", - }, - 'enc-dec(trithemius)': ["Hello, World!", "@random"], + 'enc(trithemius)': {'': "", 'HELLO': "HFNOS", '12345!@#$': "12345!@#$"}, + 'enc-dec(trithemius)': ["Hello, World!", "@random"], } __guess__ = ["trithemius"] @@ -34,11 +23,8 @@ def _trithemius(text, decode=False): r, pos = "", 0 for c in ensure_str(text): - if c in LC: - r += LC[(LC.index(c) + (-pos if decode else pos)) % 26] - pos += 1 - elif c in UC: - r += UC[(UC.index(c) + (-pos if decode else pos)) % 26] + if c in LC or c in UC: + r += (a := LC if c in LC else UC)[(a.index(c) + [1, -1][decode] * pos) % 26] pos += 1 else: r += c @@ -47,14 +33,13 @@ def _trithemius(text, decode=False): def trithemius_encode(text, errors="strict"): r = _trithemius(ensure_str(text)) - return r, len(text) + return r, len(r) def trithemius_decode(text, errors="strict"): - r = _trithemius(ensure_str(text), decode=True) - return r, len(text) + r = _trithemius(ensure_str(text), True) + return r, len(r) -add("trithemius", trithemius_encode, trithemius_decode, - r"trithemius(?:[-_]cipher)?$", - entropy=lambda e: e, printables_rate=lambda pr: pr, transitive=True) +add("trithemius", trithemius_encode, trithemius_decode, r"trithemius(?:[-_]cipher)?$", printables_rate=lambda pr: pr, + entropy=lambda e: e)