Skip to content

Add Phillips cipher codec#40

Open
Copilot wants to merge 2 commits intomainfrom
copilot/add-phillips-encoding
Open

Add Phillips cipher codec#40
Copilot wants to merge 2 commits intomainfrom
copilot/add-phillips-encoding

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

Checklist

  • No unrelated changes
  • Codec is new (not already implemented)
  • Tests included (if cannot be automated with tests/test_generated)
  • Documentation (included in the right page in docs/pages/enc)

Description

The Phillips cipher is a polyalphabetic block cipher that enciphers bigrams using a cycle of 8 key squares. The first square is a 5×5 grid filled keyword-first (I/J combined); each subsequent square rotates every row one step left. Substitution follows Playfair rules (same row → shift right/left, same column → shift down/up, rectangle → swap columns).

Implementation highlights:

  • src/codext/crypto/phillips.py — new codec:
    • Keyword-seeded 5×5 grid; 7 row-rotated variants give the 8 key squares
    • Bigrams cycle through squares 1–8 (wrapping); odd-length input padded with X
    • Non-alphabetic characters pass through in place; JI
    • Key required — LookupError deferred to call-time (consistent with Vigenère pattern, so codec listing/lookup works without a key)
    • __examples__ with verified encode values + roundtrip tests; __guess__ for guess mode
  • src/codext/crypto/__init__.py — registers the codec
  • README.md — adds entry under Cryptography
import codext

codext.encode("ATTACK", "phillips-key")   # → "BSSBIC"
codext.decode("BSSBIC", "phillips-key")   # → "ATTACK"

codext.encode("HELLO WORLD", "phillips-key")  # → "DBMMM ZMTQL"  (space preserved)
codext.decode("DBMMM ZMTQL", "phillips-key")  # → "HELLO WORLD"
Original prompt

This section details on the original issue you should resolve

<issue_title>Add new encoding: phillips</issue_title>
<issue_description>### Description

The Philips cipher is a polyalphabetic substitution cipher by blocks using 8 grids (1 initial grid and 7 others created from the first).

Reference

https://www.dcode.fr/phillips-cipher</issue_description>

<agent_instructions>Propose an implementation according to the guideline at docs/pages/howto.md.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@dhondta dhondta marked this pull request as ready for review March 25, 2026 22:16
Co-authored-by: dhondta <9108102+dhondta@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dhondta/python-codext/sessions/01837063-2248-4979-b695-b34e3bf223bf
Copilot AI changed the title [WIP] Add new encoding for Philips cipher Add Phillips cipher codec Mar 25, 2026
Copilot AI requested a review from dhondta March 25, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new encoding: phillips

2 participants