From 0ea2f16918f72f4385df629fbc85590a896e0ec0 Mon Sep 17 00:00:00 2001 From: vbetsch Date: Wed, 1 Jul 2026 00:03:15 +0200 Subject: [PATCH 1/3] test: add tests --- tests/cypher.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/cypher.test.ts b/tests/cypher.test.ts index 0951aa1..fb69887 100644 --- a/tests/cypher.test.ts +++ b/tests/cypher.test.ts @@ -6,6 +6,14 @@ describe('Cypher', () => { expect(cypher).toBeDefined(); expect(cypher).toBeInstanceOf(Cypher); }); + it('should decrypt h', () => { + const cypher: Cypher = new Cypher(); + expect(cypher.decrypt('&')).toBe('h'); + }); + it('should decrypt he', () => { + const cypher: Cypher = new Cypher(); + expect(cypher.decrypt('&£')).toBe('he'); + }); it('should decrypt hello', () => { const cypher: Cypher = new Cypher(); expect(cypher.decrypt('&£aad')).toBe('hello'); @@ -14,6 +22,14 @@ describe('Cypher', () => { const cypher: Cypher = new Cypher(); expect(cypher.decrypt('ldga(')).toBe('world'); }); + it('should encrypt h', () => { + const cypher: Cypher = new Cypher(); + expect(cypher.encrypt('h')).toBe('&'); + }); + it('should encrypt he', () => { + const cypher: Cypher = new Cypher(); + expect(cypher.encrypt('he')).toBe('&£'); + }); it('should encrypt hello', () => { const cypher: Cypher = new Cypher(); expect(cypher.encrypt('hello')).toBe('&£aad'); From 77d1395aafeeb8882036be035a420f1160a864e8 Mon Sep 17 00:00:00 2001 From: vbetsch Date: Wed, 1 Jul 2026 00:09:04 +0200 Subject: [PATCH 2/3] feat: handle cases --- src/cypher.ts | 2 +- tests/cypher.test.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cypher.ts b/src/cypher.ts index eec8389..04c2388 100644 --- a/src/cypher.ts +++ b/src/cypher.ts @@ -71,6 +71,6 @@ export class Cypher { } public encrypt(message: string): string { - return this._translate(this._alphabet, this._decryptionKey, message); + return this._translate(this._alphabet, this._decryptionKey, message.toLowerCase()); } } diff --git a/tests/cypher.test.ts b/tests/cypher.test.ts index fb69887..2e01819 100644 --- a/tests/cypher.test.ts +++ b/tests/cypher.test.ts @@ -1,4 +1,4 @@ -import { Cypher } from '@src/cypher'; +import {Cypher} from '@src/cypher'; describe('Cypher', () => { it('should be OK', () => { @@ -38,4 +38,8 @@ describe('Cypher', () => { const cypher: Cypher = new Cypher(); expect(cypher.encrypt('world')).toBe('ldga('); }); + it('should handle cases', () => { + const cypher: Cypher = new Cypher(); + expect(cypher.encrypt('Hello')).toBe('&£aad'); + }); }); From 817efa6b5bf222ef86a5bc8f64c261bdd36f251a Mon Sep 17 00:00:00 2001 From: vbetsch Date: Wed, 1 Jul 2026 00:13:01 +0200 Subject: [PATCH 3/3] feat: handle unknown characters --- src/cypher.ts | 1 + src/index.ts | 4 ++++ tests/cypher.test.ts | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/cypher.ts b/src/cypher.ts index 04c2388..dc4d960 100644 --- a/src/cypher.ts +++ b/src/cypher.ts @@ -61,6 +61,7 @@ export class Cypher { for (let i = 0; i < message.length; i++) { const char: string = message.charAt(i); const index: number = dictSource.indexOf(char); + if(!dictTarget[index]) continue; result += dictTarget[index]; } return result; diff --git a/src/index.ts b/src/index.ts index a420803..4121ad7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,5 @@ +import {Cypher} from "@src/cypher"; + console.log('Hello World!'); +const cypher: Cypher = new Cypher(); +console.log(cypher.encrypt('Hello World!')); diff --git a/tests/cypher.test.ts b/tests/cypher.test.ts index 2e01819..bf21c57 100644 --- a/tests/cypher.test.ts +++ b/tests/cypher.test.ts @@ -42,4 +42,8 @@ describe('Cypher', () => { const cypher: Cypher = new Cypher(); expect(cypher.encrypt('Hello')).toBe('&£aad'); }); + it('should handle unknown characters', () => { + const cypher: Cypher = new Cypher(); + expect(cypher.encrypt('Hello !')).toBe('&£aad'); + }); });