Skip to content

Commit 8d2cffc

Browse files
authored
test: cover KeywordShiftedAlphabet keywords with repeated characters
Regression tests for the validation fix: 'HELLO' (repeated L) must throw on encrypt and decrypt, and 'Kk' must throw because the translation table is built from the lowercased keyword.
1 parent 6507502 commit 8d2cffc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎Ciphers/test/KeywordShiftedAlphabet.test.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ test('The Algorithms === decrypt(encrypt(The Algorithms))', () => {
1111
const result = decrypt('keyword', encrypt('keyword', word))
1212
expect(result).toMatch(word)
1313
})
14+
15+
test('rejects keywords with repeated characters', () => {
16+
// 'HELLO' repeats L; encrypt must throw instead of producing
17+
// ciphertext that cannot be decrypted back
18+
expect(() => encrypt('HELLO', 'ATTACK AT DAWN')).toThrow('Invalid keyword!')
19+
expect(() => decrypt('HELLO', 'HSSHLG HS LHVK')).toThrow('Invalid keyword!')
20+
})
21+
22+
test('rejects keywords that repeat a character in another case', () => {
23+
// the table is built from the lowercased keyword, so 'Kk' is a duplicate
24+
expect(() => encrypt('Kk', 'ATTACK')).toThrow('Invalid keyword!')
25+
})

0 commit comments

Comments
 (0)