@irfanshadikrishad/cipher 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/Cipher.d.ts +3 -1
- package/dist/ciphers/Alphabet.d.ts +22 -0
- package/dist/ciphers/Alphabet.js +65 -0
- package/dist/index.js +3 -1
- package/package.json +18 -4
- /package/dist/ciphers/{Ceaser.d.ts → Caesar.d.ts} +0 -0
- /package/dist/ciphers/{Ceaser.js → Caesar.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
#### @irfanshadikrishad/cipher
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A versatile and secure cryptographic library for implementing various cipher algorithms in Node.js applications.
|
|
4
|
+
|
|
5
|
+
#### Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @irfanshadikrishad/cipher
|
|
9
|
+
```
|
|
4
10
|
|
|
5
11
|
#### Usage
|
|
6
12
|
|
|
@@ -9,7 +15,7 @@ import { Cipher } from "@irfanshadikrishad/cipher"
|
|
|
9
15
|
|
|
10
16
|
const ceaser = new Cipher.Ceaser(6)
|
|
11
17
|
|
|
12
|
-
console.log(ceaser.encrypt("
|
|
18
|
+
console.log(ceaser.encrypt("hello world"))
|
|
13
19
|
```
|
|
14
20
|
|
|
15
21
|
#### Available Ciphers
|
|
@@ -18,5 +24,7 @@ console.log(ceaser.encrypt("abx"))
|
|
|
18
24
|
- Atbash Cipher
|
|
19
25
|
- Playfair Cipher
|
|
20
26
|
- Vigenere Cipher
|
|
27
|
+
- The Alphabet Cipher
|
|
28
|
+
- & more coming soon ...
|
|
21
29
|
|
|
22
30
|
#### Thanks for visiting (>'-'<)
|
package/dist/Cipher.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { Caesar } from "./ciphers/
|
|
1
|
+
import { Caesar } from "./ciphers/Caesar.js";
|
|
2
2
|
import { Atbash } from "./ciphers/Atbash.js";
|
|
3
3
|
import { Playfair } from "./ciphers/Playfair.js";
|
|
4
4
|
import { Vigenere } from "./ciphers/Vigenere.js";
|
|
5
|
+
import { Alphabet } from "./ciphers/Alphabet.js";
|
|
5
6
|
export declare abstract class Cipher {
|
|
6
7
|
static Caesar: typeof Caesar;
|
|
7
8
|
static Atbash: typeof Atbash;
|
|
8
9
|
static Playfair: typeof Playfair;
|
|
9
10
|
static Vigenere: typeof Vigenere;
|
|
11
|
+
static Alphabet: typeof Alphabet;
|
|
10
12
|
abstract encrypt(text: string): string;
|
|
11
13
|
abstract decrypt(text: string): string;
|
|
12
14
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Cipher } from "../Cipher.js";
|
|
2
|
+
export declare class Alphabet extends Cipher {
|
|
3
|
+
private keyword;
|
|
4
|
+
private static alphabet;
|
|
5
|
+
constructor(keyword: string);
|
|
6
|
+
/**
|
|
7
|
+
* Encrypts a message using the Alphabet Cipher.
|
|
8
|
+
* @param message - The plaintext message to encrypt.
|
|
9
|
+
* @returns The encrypted ciphertext.
|
|
10
|
+
*/
|
|
11
|
+
encrypt(message: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Decrypts a message using the Alphabet Cipher.
|
|
14
|
+
* @param ciphertext - The encrypted message to decrypt.
|
|
15
|
+
* @returns The original plaintext message.
|
|
16
|
+
*/
|
|
17
|
+
decrypt(ciphertext: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generates the Vigenère table for encoding and decoding.
|
|
20
|
+
*/
|
|
21
|
+
private static getVigenereTable;
|
|
22
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Cipher } from "../Cipher.js";
|
|
2
|
+
export class Alphabet extends Cipher {
|
|
3
|
+
constructor(keyword) {
|
|
4
|
+
super();
|
|
5
|
+
this.keyword = keyword.toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Encrypts a message using the Alphabet Cipher.
|
|
9
|
+
* @param message - The plaintext message to encrypt.
|
|
10
|
+
* @returns The encrypted ciphertext.
|
|
11
|
+
*/
|
|
12
|
+
encrypt(message) {
|
|
13
|
+
message = message.toLowerCase();
|
|
14
|
+
const table = Alphabet.getVigenereTable();
|
|
15
|
+
let result = "";
|
|
16
|
+
for (let i = 0; i < message.length; i++) {
|
|
17
|
+
const msgChar = message[i];
|
|
18
|
+
const keyChar = this.keyword[i % this.keyword.length];
|
|
19
|
+
if (!Alphabet.alphabet.includes(msgChar)) {
|
|
20
|
+
result += msgChar; // Preserve non-alphabet characters
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const row = Alphabet.alphabet.indexOf(keyChar);
|
|
24
|
+
const col = Alphabet.alphabet.indexOf(msgChar);
|
|
25
|
+
result += table[row][col];
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decrypts a message using the Alphabet Cipher.
|
|
31
|
+
* @param ciphertext - The encrypted message to decrypt.
|
|
32
|
+
* @returns The original plaintext message.
|
|
33
|
+
*/
|
|
34
|
+
decrypt(ciphertext) {
|
|
35
|
+
ciphertext = ciphertext.toLowerCase();
|
|
36
|
+
const table = Alphabet.getVigenereTable();
|
|
37
|
+
let result = "";
|
|
38
|
+
for (let i = 0; i < ciphertext.length; i++) {
|
|
39
|
+
const cipherChar = ciphertext[i];
|
|
40
|
+
const keyChar = this.keyword[i % this.keyword.length];
|
|
41
|
+
if (!Alphabet.alphabet.includes(cipherChar)) {
|
|
42
|
+
result += cipherChar; // Preserve non-alphabet characters
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const row = Alphabet.alphabet.indexOf(keyChar);
|
|
46
|
+
const col = table[row].indexOf(cipherChar);
|
|
47
|
+
result += Alphabet.alphabet[col];
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generates the Vigenère table for encoding and decoding.
|
|
53
|
+
*/
|
|
54
|
+
static getVigenereTable() {
|
|
55
|
+
const table = [];
|
|
56
|
+
for (let i = 0; i < 26; i++) {
|
|
57
|
+
table[i] = Alphabet.alphabet
|
|
58
|
+
.slice(i)
|
|
59
|
+
.split("")
|
|
60
|
+
.concat(Alphabet.alphabet.slice(0, i).split(""));
|
|
61
|
+
}
|
|
62
|
+
return table;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
Alphabet.alphabet = "abcdefghijklmnopqrstuvwxyz";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Cipher } from "./Cipher.js";
|
|
2
|
-
import { Caesar } from "./ciphers/
|
|
2
|
+
import { Caesar } from "./ciphers/Caesar.js";
|
|
3
3
|
import { Atbash } from "./ciphers/Atbash.js";
|
|
4
4
|
import { Playfair } from "./ciphers/Playfair.js";
|
|
5
5
|
import { Vigenere } from "./ciphers/Vigenere.js";
|
|
6
|
+
import { Alphabet } from "./ciphers/Alphabet.js";
|
|
6
7
|
Cipher.Caesar = Caesar;
|
|
7
8
|
Cipher.Atbash = Atbash;
|
|
8
9
|
Cipher.Playfair = Playfair;
|
|
9
10
|
Cipher.Vigenere = Vigenere;
|
|
11
|
+
Cipher.Alphabet = Alphabet;
|
|
10
12
|
export { Cipher };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irfanshadikrishad/cipher",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "A versatile and secure cryptographic library for implementing various cipher algorithms in Node.js applications.",
|
|
5
5
|
"homepage": "https://github.com/irfanshadikrishad/cipher#readme",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/irfanshadikrishad/cipher/issues"
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
|
+
"directories": {
|
|
17
|
+
"test": "test",
|
|
18
|
+
"lib": "src"
|
|
19
|
+
},
|
|
16
20
|
"license": "MPL-2.0",
|
|
17
21
|
"author": {
|
|
18
22
|
"name": "Irfan Shadik Rishad"
|
|
@@ -31,18 +35,28 @@
|
|
|
31
35
|
"format": "prettier . --write",
|
|
32
36
|
"lint": "eslint . --ext .ts",
|
|
33
37
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
34
|
-
"test": "
|
|
38
|
+
"test": "jest ./tests",
|
|
35
39
|
"prepare": "husky"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@eslint/js": "^9.21.0",
|
|
43
|
+
"@types/jest": "^29.5.14",
|
|
39
44
|
"@typescript-eslint/eslint-plugin": "^8.26.0",
|
|
40
45
|
"@typescript-eslint/parser": "^8.26.0",
|
|
41
46
|
"eslint": "^9.21.0",
|
|
42
47
|
"globals": "^16.0.0",
|
|
43
48
|
"husky": "^9.1.7",
|
|
49
|
+
"jest": "^29.7.0",
|
|
44
50
|
"prettier": "^3.5.3",
|
|
51
|
+
"ts-jest": "^29.2.6",
|
|
45
52
|
"typescript": "^5.8.2",
|
|
46
53
|
"typescript-eslint": "^8.26.0"
|
|
47
|
-
}
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"security",
|
|
57
|
+
"cipher",
|
|
58
|
+
"cryptography",
|
|
59
|
+
"encryption",
|
|
60
|
+
"decryption"
|
|
61
|
+
]
|
|
48
62
|
}
|
|
File without changes
|
|
File without changes
|