Skip to content

Add cipher consistency, validation feedback, and solution reveal to frequency analysis tool#2

Draft
vladimirlopez with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-sample-text-encryption
Draft

Add cipher consistency, validation feedback, and solution reveal to frequency analysis tool#2
vladimirlopez with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-sample-text-encryption

Conversation

Copilot AI commented Jan 22, 2026

Copy link
Copy Markdown

Sample encrypted texts were inconsistently encrypted, making them unsolvable. The tool lacked feedback mechanisms to guide users through the decryption process.

Changes

Cipher System

  • Implemented consistent substitution cipher (QWERTYUIOPASDFGHJKLZXCVBNM)
  • Regenerated all language samples (EN, ES, FR, DE) with encryptText()
  • Created solutionMappings object for validation

Real-time Validation

  • Added validateSubstitutions() to compare user input against correct mappings
  • Visual feedback: green border for correct, red for incorrect substitutions
  • Progress indicator displays "Correct: X/Y Accuracy: Z%"
  • Only active when sample text is loaded

Show Solution Feature

  • Button in header, disabled for custom input
  • Confirmation dialog before revealing complete solution
  • Auto-fills all correct mappings on confirmation

UI

Validation feedback with progress tracking:
Validation

Solution revealed (22/22 correct):
Solution

Implementation

// Consistent cipher mapping
const PLAIN_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const CIPHER_ALPHABET = 'QWERTYUIOPASDFGHJKLZXCVBNM';

// Validation tracks sample state
let isSampleLoaded = false;

function validateSubstitutions() {
    if (!isSampleLoaded) return null;
    
    const encryptedText = inputText.value.toUpperCase().replace(/[^A-Z]/g, '');
    const uniqueLetters = [...new Set(encryptedText)];
    
    uniqueLetters.forEach(encryptedChar => {
        const userSub = substitutions[encryptedChar];
        const correctSub = solutionMappings[encryptedChar];
        // Compare and return validation results
    });
}

Files modified: main.js (+204 lines), index.html (+4 lines), style.css (+28 lines)

Original prompt

Problem

The frequency analysis simulation has issues with the sample encrypted texts and lacks features to help users validate their work. Based on the decoded output shown in image1, the substitution mappings are producing incorrect results.

Required Changes

1. Fix Sample Text Encryption Logic

The sample texts in main.js (lines 33-38) need to be properly encrypted with a consistent, verifiable cipher. Currently, when users try to decode the samples, they get inconsistent results.

Requirements:

  • Create a proper cipher function that uses a consistent substitution alphabet
  • Regenerate all sample encrypted texts (English, Spanish, French, German) using this cipher
  • Store the correct decryption mappings for each sample so they can be verified
  • Use a Caesar-like shift or a fixed substitution alphabet that is consistent across all samples

Suggested cipher alphabet for consistency:

Plain:  ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: QWERTYUIOPASDFGHJKLZXCVBNM

Or use a consistent Caesar shift (e.g., +3).

2. Add Validation and Hints

Add visual feedback to help users know when they're on the right track:

Requirements:

  • When a user enters a substitution mapping, validate it against the known correct mapping for sample texts
  • Add visual indicators (e.g., green highlight for correct mappings, red for incorrect)
  • Add a hint system that shows how many letters are correctly mapped (e.g., "5/26 letters correct")
  • Add a progress indicator in the decoded view showing accuracy percentage
  • Only validate when using sample texts (not custom encrypted input)

UI Changes needed:

  • Add a status message below the substitution grid showing validation feedback
  • Color-code the substitution input boxes: green border for correct, red for incorrect (only for samples)
  • Add a small counter showing "Correct: X/Y" where Y is the number of unique letters in the encrypted sample

3. Add "Show Solution" Button

Add a button that reveals the correct substitution mappings for educational purposes:

Requirements:

  • Add a "Show Solution" button next to the existing control buttons
  • When clicked, automatically fill in all correct substitution mappings for the current sample
  • Only enable this button when a sample text is loaded (disable for custom input)
  • Add a confirmation dialog: "Are you sure? This will reveal the complete solution."
  • After showing solution, maybe add a visual indication that solution was revealed

Button placement:
Add it in the header controls section next to "Reset All" button in index.html

4. Technical Implementation Notes

In main.js:

  • Create a solutionMappings object that stores the correct decryption key for each language sample
  • Create a validateSubstitutions() function that compares current substitutions against the solution
  • Create a showSolution() function that fills in all correct mappings
  • Update updateDecodedDisplay() to show validation feedback
  • Add a flag isSampleLoaded to track if a sample is currently loaded

In index.html:

  • Add the new button and validation UI elements

In style.css:

  • Add styles for validation feedback (green/red borders, success/error messages)
  • Style the new "Show Solution" button
  • Add styles for the progress indicator

Example Output

After fixes, users should be able to:

  1. Load a sample and see it properly encrypted
  2. Enter substitutions and see immediate feedback (green for correct, red for incorrect)
  3. See their progress (e.g., "12/26 letters correct - 85% accuracy")
  4. Click "Show Solution" to reveal the complete mapping for learning

Files to Modify

  • main.js - Main logic changes
  • index.html - Add new UI elements
  • style.css - Add validation styling

This pull request was created from Copilot chat.


💡 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.

Co-authored-by: vladimirlopez <43343770+vladimirlopez@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sample text encryption logic for consistent results Add cipher consistency, validation feedback, and solution reveal to frequency analysis tool Jan 22, 2026
Copilot AI requested a review from vladimirlopez January 22, 2026 21:30
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