moh-hasher 1.0.0

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.
Files changed (2) hide show
  1. package/index.js +44 -0
  2. package/package.json +13 -0
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ // moh-hasher/index.js
2
+
3
+ // Custom encoding map where small and capital letters have unique hash values
4
+ const encodeMap = {
5
+ 'a': '@1', 'b': '#2', 'c': '$3', 'd': '%4', 'e': '&5', 'f': '*6', 'g': '(7', 'h': ')8',
6
+ 'i': '!9', 'j': '-10', 'k': '=11', 'l': '+12', 'm': '[13', 'n': ']14', 'o': '{15', 'p': '}16',
7
+ 'q': '^17', 'r': '~18', 's': '>19', 't': '<20', 'u': '?21', 'v': '/22', 'w': '\\23', 'x': '|24',
8
+ 'y': ';25', 'z': ':26',
9
+ 'A': '@A1', 'B': '#B2', 'C': '$C3', 'D': '%D4', 'E': '&E5', 'F': '*F6', 'G': '(G7', 'H': ')H8',
10
+ 'I': '!I9', 'J': '-J10', 'K': '=K11', 'L': '+L12', 'M': '[M13', 'N': ']N14', 'O': '{O15', 'P': '}P16',
11
+ 'Q': '^Q17', 'R': '~R18', 'S': '>S19', 'T': '<T20', 'U': '?U21', 'V': '/V22', 'W': '\\W23', 'X': '|X24',
12
+ 'Y': ';Y25', 'Z': ':Z26',
13
+ '0': 'a1', '1': 'b2', '2': 'c3', '3': 'd4', '4': 'e5', '5': 'f6', '6': 'g7', '7': 'h8',
14
+ '8': 'i9', '9': 'j10',
15
+ '!': 'k11', '@': 'l12', '#': 'm13', '$': 'n14', '%': 'o15', '^': 'p16', '&': 'q17', '*': 'r18',
16
+ '(': 's19', ')': 't20', '-': 'u21', '=': 'v22', '+': 'w23', '[': 'x24', ']': 'y25', '{': 'z26',
17
+ '}': '0A1', ' ': '0B2', '.': '0C3', ',': '0D4', '?': '0E5', '!': '0F6', ';': '0G7', ':': '0H8',
18
+ '"': '0I9', "'": '0J10'
19
+ };
20
+
21
+ // Reverse the encodeMap to decode
22
+ const decodeMap = Object.fromEntries(
23
+ Object.entries(encodeMap).map(([key, value]) => [value, key])
24
+ );
25
+
26
+ // Hasher (encode)
27
+ export function hash(secret) {
28
+ let encoded = '';
29
+ for (let i = 0; i < secret.length; i++) {
30
+ const char = secret[i];
31
+ encoded += encodeMap[char] || char; // Default to the char if not found in the map
32
+ }
33
+ return encoded;
34
+ }
35
+
36
+ // Unhasher (decode)
37
+ export function unhash(encodedSecret) {
38
+ let decoded = '';
39
+ for (let i = 0; i < encodedSecret.length; i++) {
40
+ const char = encodedSecret[i];
41
+ decoded += decodeMap[char] || char; // Default to the char if not found in the map
42
+ }
43
+ return decoded;
44
+ }
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "moh-hasher",
3
+ "version": "1.0.0",
4
+ "description": "A simple encoding and decoding package with unique hashes",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": ["hash", "encode", "decode", "cipher"],
11
+ "author": "Mohas",
12
+ "license": "MIT"
13
+ }