18suite(
'Ciphers Hardening', () => {
19 test(
'should expose at least 30 ciphers', () => {
21 const list = c.listCiphers();
22 assert.ok(list.length >= 30, `Expected >=30
ciphers, got ${list.length}: ${list.join(
', ')}`);
25 test(
'every flavoured cipher should have CipherName and encode/decode as functions', () => {
27 for (
const Cls of instances as any[]) {
28 const inst =
new Cls();
29 assert.ok(typeof inst.CipherName ===
'string' && inst.CipherName.length > 0, `${Cls.name} missing CipherName`);
30 assert.strictEqual(typeof inst.encode,
'function', `${Cls.name}.encode should be
function`);
31 assert.strictEqual(typeof inst.decode,
'function', `${Cls.name}.decode should be
function`);
35 test(
'Cipher registry should round-trip for keyless ciphers (Caesar, ROT13, Atbash, Base64)', () => {
37 const plain =
'HELLO WORLD';
39 for (
const name of [
'caesar',
'rot13',
'atbash',
'base64']) {
40 const enc = c.encode(plain, undefined, name);
41 assert.strictEqual(typeof enc,
'string', `${name} encode should
return string`);
42 assert.ok(enc.length > 0, `${name} encode should not be empty`);
43 const dec = c.decode(enc, undefined, name);
44 assert.strictEqual(typeof dec,
'string', `${name} decode should
return string`);
46 if (name ===
'base64') {
47 assert.strictEqual(dec, plain,
'Base64 round-trip should be exact');
50 assert.ok(dec.includes(
'HELLO'), `${name} round-trip should contain HELLO, got ${dec}`);
55 test(
'should throw on unknown cipher and on missing name', () => {
57 assert.throws(() => c.encode(
'hi', undefined, undefined as any), /
Cipher name required/);
58 assert.throws(() => c.encode(
'hi', undefined,
'nonexistent'), /not found/);
59 assert.throws(() => c.decode(
'hi', undefined, undefined as any), /
Cipher name required/);
60 assert.throws(() => c.decode(
'hi', undefined,
'nonexistent'), /not found/);
63 test(
'listCiphers keys should be normalized lower-case without spaces', () => {
65 const list = c.listCiphers();
66 for (
const k of list) {
67 assert.strictEqual(k, k.toLowerCase(), `${k} should be lower-
case`);
68 assert.ok(!k.includes(
' '), `${k} should not contain spaces`);
72 test(
'encode/decode should handle empty string without throwing (all ciphers)', () => {
74 const list = c.listCiphers();
76 const candidateKeys: (
string | undefined)[] = [undefined,
'KEY',
'123',
'TESTKEY',
'A'];
77 for (
const name of list) {
79 let lastEncodeError: any =
null;
80 for (
const k of candidateKeys) {
82 c.encode(
'', k as any, name);
90 assert.ok(encodeOk, `${name} encode(
'') should handle empty
string with some valid key, last error: ${lastEncodeError}`);
93 let lastDecodeError: any =
null;
94 for (
const k of candidateKeys) {
96 c.decode(
'', k as any, name);
103 assert.ok(decodeOk, `${name} decode(
'') should handle empty
string with some valid key, last error: ${lastDecodeError}`);
import *as assert from assert
export const ALLCiphers
Comprehensive object containing all cipher classes and utilities.
Central cipher management class providing unified access to all cipher implementations.