Repository navigation
R50-T002: Define the supported boundaries of checkKeywordValidity (KeywordShiftedAlphabet.js) [Ciphers/KeywordShiftedAlphabet.js] - #100
Open
stavansomaiya wants to merge 1 commit into
Conversation
…est boundaries (R50-T002) Fixes: S-AI-Projects#2
This was referenced Nov 23, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
e26b07f1064Ciphers/KeywordShiftedAlphabet.js→checkKeywordValidity(line 48 at the pinned commit, line 65 after this PR)5c39e87·KeywordShiftedAlphabet.js#L48stavansomaiya:student/e26b07f1064/R50-T002→S-AI-Projects:master(one commit on5c39e87)return falseinsideforEachwas ignored (forEach→every).Summary
Makes the supported boundary of
checkKeywordValidityexplicit, and fixes the defect that the boundary tests exposed. The file states "Keyword must be a word where each character can occur only once" (line 3). Butreturn falseinsideforEachonly returned from the callback, so the function always returnedtrue. Repeated-letter keywords were accepted and the cipher no longer round-tripped: on the original code,decrypt('hello', encrypt('hello', 'd'))returned'c'.Files changed
Ciphers/KeywordShiftedAlphabet.jsforEach→everyfix, boundary JSDoc, export, two header typos fixedCiphers/test/KeywordShiftedAlphabet.test.jswork/R50-T002/(10 files)check.pyrunner,README.mdwrite-up,evidence.mjs,results.jsonand logs; coursework only, kept out of any upstream PRRelated Issue
Fixes: #2
This PR covers only R50-T002. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.
Type of Change
Changes Made
Ciphers/KeywordShiftedAlphabet.js:forEachreplaced byevery, which returnsfalseon the first repeated character. Same algorithm and same case-sensitive comparison; no other guard changed. JSDoc documents the supported boundaries.checkKeywordValidityis now also exported for testing;encryptanddecryptare unchanged. Two typos in the file header are fixed: the table row listedWtwice and omittedX, and the decryption example was missing a letter (Aogg→Aoggj).Ciphers/test/KeywordShiftedAlphabet.test.js: a test on each side of the boundary. Valid:'a'(smallest),'keyword'(ordinary), all 26 letters (largest). Invalid:'aa','hello'and 27 letters, which returnfalseand makeencrypt/decryptthrowInvalid keyword!. Unsupported:'', whichcheckInputsrejects first.work/R50-T002/:check.py, the boundary table (README),baseline.txt(original behaviour),negative-control.txt,evidence.mjsand results.Screenshots / Recordings
There is no UI, so the recording is the terminal output of a fresh run on 23 Nov 2026. The run used a clean checkout of this branch with a new
npm cifrom the lockfile. The output is copied verbatim; only the temporary checkout path is replaced by a label.Focused tests:
npx vitest run … --reporter=verbose, 9/9 passedAutomated check:
python3 work/R50-T002/check.py, exit 0Testing
Automated check:
python3 work/R50-T002/check.pyinstalls from the lockfile and runs the focused tests. It then prints input / expected / actual for every fixture row, runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode. It exits non-zero if any assertion or step fails, and records every command incommands.log.To reproduce:
Recorded results (committed in
results.json; tool versions inversions.txt):npm ci --ignore-scripts --no-audit --no-fundvitest run Ciphers/test/KeywordShiftedAlphabet.test.jsnode work/R50-T002/evidence.mjscheck.pysmallest repeated keyword 'aa' is rejectednpm test(vitest run)npm run check-style(Prettier)codespellAcceptance criteria → evidence:
checkKeywordValidityin Ciphers/KeywordShiftedAlphabet.js; every assertion has an explicit expected value.describe('checkKeywordValidity boundaries')call the exportedcheckKeywordValidityand assert literaltrue/false, plus literal results throughencrypt/decrypt('abc','Aoggj ujngw!','zyx','Invalid keyword!').checkKeywordValidityfrom Ciphers/KeywordShiftedAlphabet.js. Write the literal inputs and independently calculated expected outputs in the tests before editing the implementation. The check must name the source line establishing each precondition.'a'→true; ordinary'keyword'→truewithencrypt('keyword', 'Hello world!') === 'Aoggj ujngw!'. Expected values come from the contract at line 3 and were recorded before running; the original's behaviour is saved inbaseline.txt. Each boundary-table row names its source line (3, 8, 99-100, 104).negative-control.txtshowscheck.pyexiting 1 on the original logic, with the 3 repeated-keyword tests failing. Defect, cause and fix are documented in the README and JSDoc.encrypt/decryptare unchanged and the 2 existing round-trip tests pass.forEach→everyinsidecheckKeywordValidity. The errors asserted are the file's existingInvalid keyword!andBoth keyword and message must be specified. Cases the source leaves undefined, such as'Aa', get no new rule.Evidence files:
check.py·README.md(contract, fixture, baseline, findings) ·evidence.mjs·results.json·vitest-focused.jsonChecklist
Additional Notes
negative-control.txtshowscheck.pyexiting 1 with the original always-truebehaviour: the 3 repeated-keyword tests fail and the other 6 pass.check.pyalso re-applies that defect to a temporary copy on every run and requiressmallest repeated keyword 'aa' is rejectedto fail on it. No rule was added for cases the source leaves undefined, such as mixed-case repeats like'Aa', and no TypeError/RangeError policy was introduced.Scope: the PR changes only
Ciphers/KeywordShiftedAlphabet.js, its test file andwork/R50-T002/.work/R50-T002/is coursework evidence and would be removed from any later upstream PR.All 10 tasks (one PR each)
R50-T001R50-T002R50-T003R50-T004R50-T005R50-T006R50-T007R50-T008R50-T009R50-T010