Skip to content

Fix non-bijective cipher mapping and add bidirectional encoding#1

Draft
vladimirlopez with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-encoding-logic
Draft

Fix non-bijective cipher mapping and add bidirectional encoding#1
vladimirlopez with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-encoding-logic

Conversation

Copilot AI commented Jan 22, 2026

Copy link
Copy Markdown

The English sample cipher had non-bijective mappings causing incorrect decoding (e.g., both 'I' and 'N' mapped to the same ciphertext letter, producing "HY ANY GIVEN STRETHH" instead of "IN ANY GIVEN STRETCH").

Changes

Fixed cipher text mapping

  • Replaced sample with proper 1:1 substitution where each plaintext letter maps to exactly one unique ciphertext letter
  • Old: YKTJXTFEN QFQSNLOL OL WQLTR GF ZIT YQEZ... (collision: I→O, N→O)
  • New: GRTCVTOJD QOQSDYPY PY MQYTZ XO EKT GQJE... (bijective)

Added encode feature

  • New textarea accepts plaintext input
  • Real-time encoding using inverse of current substitution mapping
  • Copy button for encoded output
  • Updates automatically when user modifies substitution mappings
// Reverse the substitution mapping for encoding
const reverseSubstitutions = {};
for (const encryptedChar in substitutions) {
    const decodedChar = substitutions[encryptedChar];
    if (decodedChar) {
        reverseSubstitutions[decodedChar] = encryptedChar;
    }
}

Screenshot

Encode feature showing bidirectional substitution

Students can now both decode encrypted messages and encode plaintext using their discovered substitutions.

Original prompt

The sample text is not correctly encoded. When I decoded with the frequency analysis tool I get this FREQUENCY ANALYSIS IS BASED ON THE FACT THAT, HY ANY GIVEN STRETHH OF VRHTTEN LANGUAGE, CERTAHN LETTERS AND COMBINATIONS OF LETTERS OCCUR VITH VARYHNG FREQUENCES. MOREOVER, THERE IS A CHARACTERISTHE DISTRIUUTION OF LETTERS THAT IS ROUGHLP THE SAME FOR ALMOST ALL SAMPLSL OF THAT LANGUAGE. I think that more than one letter are assigned to the same. Review the logic and fix it. Then add the hability for the user to select the substitution and show the encoded message.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: vladimirlopez <43343770+vladimirlopez@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix encoding logic and add user substitution selection Fix non-bijective cipher mapping and add bidirectional encoding Jan 22, 2026
Copilot AI requested a review from vladimirlopez January 22, 2026 19:39
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.

2 participants