Skip to content

Add Playfair cipher codec#38

Draft
dhondta with Copilot wants to merge 3 commits into
mainfrom
copilot/add-playfair-encoding
Draft

Add Playfair cipher codec#38
dhondta with Copilot wants to merge 3 commits into
mainfrom
copilot/add-playfair-encoding

Conversation

Copilot AI commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

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

Playfair is a classical symmetric cipher invented by Charles Wheatstone (1854), using bigram substitution on a 5×5 key grid (I/J share a cell). Encoding rules: same row → shift right, same column → shift down, rectangle → swap columns. Decoding reverses each rule. Repeated-letter pairs receive an X filler (Q if the letter is X); odd-length input gets a trailing filler.

Reference: https://www.dcode.fr/playfair-cipher

New codec: crypto/playfair

  • Pattern: ^playfair(?:[-_]cipher)?(?:[-_]([a-zA-Z]+))?$
    • playfair — default alphabet, no key reordering
    • playfair-<key> — keyword-derived grid
  • J→I normalization applied on both encode and decode
  • Non-alpha characters are stripped (cipher operates purely on letter pairs)
import codext

# Classic Wikipedia example (key="PLAYFAIREXAMPLE")
codext.encode("HIDETHEGOLDINTHETREESTUMP", "playfair-playfairexample")
# → 'BMODZBXDNABEKUDMUIXMMOUVIF'

codext.decode("BMODZBXDNABEKUDMUIXMMOUVIF", "playfair-playfairexample")
# → 'HIDETHEGOLDINTHETREXESTUMP'  (X filler visible where EE was split)

# Roundtrip (no repeated-letter pairs, even length)
codext.decode(codext.encode("INSTRUMENT", "playfair-keyword"), "playfair-keyword")
# → 'INSTRUMENT'

__examples__ covers enc, dec, and enc-dec roundtrip; auto-registered via crypto/__init__.py.

Original prompt

This section details on the original issue you should resolve

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

The Playfair cipher is a symmetric encryption method based on polygram substitution using grids. The Playfair cipher is a symmetric encryption method using polygram substitution using bigrams (pairs of letters), invented in 1854 by Charles Wheatstone, but popularized by his friend Lord Playfair, hence its name.

Reference

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

<agent_instructions>Refer to the guideline at docs/pages/howto.md.</agent_instructions>

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: dhondta <9108102+dhondta@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dhondta/python-codext/sessions/4b40b433-0112-42bf-ad61-b7d0d380bc9c
Copilot AI changed the title [WIP] Add new encoding: Playfair Mar 23, 2026
Copilot AI requested a review from dhondta March 23, 2026 23:25
@dhondta dhondta force-pushed the main branch 3 times, most recently from d232268 to b5414ec Compare March 29, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants