Skip to content

Add Playfair cipher codec - #38

Merged
dhondta merged 6 commits into
mainfrom
copilot/add-playfair-encoding
Jul 19, 2026
Merged

Add Playfair cipher codec#38
dhondta merged 6 commits into
mainfrom
copilot/add-playfair-encoding

Conversation

CopilotAI 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)
importcodext# 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
CopilotAI changed the title [WIP] Add new encoding: PlayfairAdd Playfair cipher codecMar 23, 2026
CopilotAI requested a review from dhondtaMarch 23, 2026 23:25
@dhondta
dhondtaforce-pushed the main branch 3 times, most recently from d232268 to b5414ecCompareMarch 29, 2026 21:01
@dhondta

Copy link
Copy Markdown
Owner

@copilot please remove Vigenere from this PR and add the documentation for the Playfair cipher.

CopilotAI commented Jul 12, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot please remove Vigenere from this PR and add the documentation for the Playfair cipher.

Done in commit a27258b: removed the Vigenere additions from this PR and added Playfair documentation in README.md and docs/pages/enc/crypto.md.

@dhondta

Copy link
Copy Markdown
Owner

@copilot please refactor the code so that it exactly implements the Playfair cipher from Dcode (https://www.dcode.fr/playfair-cipher) and try to integrate it with src/codext/crypto/phillips.py if possible.

Updated the documentation for various cryptographic ciphers implemented in `codext`, including details on encoding, parameters, and examples for each cipher.
@dhondta
dhondta marked this pull request as ready for review July 18, 2026 15:05
@mergify

mergifyBot commented Jul 18, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@dhondta
dhondta merged commit 9b3919e into mainJul 19, 2026
11 checks passed
Sign up for freeto 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: playfair

2 participants

@dhondta