j-crypto-change 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.
- package/READ.md +7 -0
- package/autopush.sh +11 -0
- package/package.json +17 -0
- package/src/index.js +46 -0
package/READ.md
ADDED
package/autopush.sh
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "j-crypto-change",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "This package was developed to enable programmers to encode and decode messages using a numerical cipher method.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "Ejiro Jacob Oshevire",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"cipher",
|
|
13
|
+
"encryption",
|
|
14
|
+
"caesar",
|
|
15
|
+
"security"
|
|
16
|
+
]
|
|
17
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
// src/index.js
|
|
4
|
+
|
|
5
|
+
// Helper to shift a single character
|
|
6
|
+
function shiftChar(char, shift) {
|
|
7
|
+
const isUpper = char >= "A" && char <= "Z";
|
|
8
|
+
const isLower = char >= "a" && char <= "z";
|
|
9
|
+
|
|
10
|
+
if (!isUpper && !isLower) return char;
|
|
11
|
+
|
|
12
|
+
const base = isUpper ? 65 : 97;
|
|
13
|
+
const charCode = char.charCodeAt(0) - base;
|
|
14
|
+
|
|
15
|
+
const shifted = (charCode + shift) % 26;
|
|
16
|
+
const normalized = shifted < 0 ? shifted + 26 : shifted;
|
|
17
|
+
|
|
18
|
+
return String.fromCharCode(normalized + base);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Encode function
|
|
22
|
+
function encode(text, shift = 3) {
|
|
23
|
+
return text
|
|
24
|
+
.split("")
|
|
25
|
+
.map((char) => shiftChar(char, shift))
|
|
26
|
+
.join("");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Decode function
|
|
30
|
+
function decode(text, shift = 3) {
|
|
31
|
+
return encode(text, -shift);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Optional: framework-style wrapper
|
|
35
|
+
function createCipher(shift = 3) {
|
|
36
|
+
return {
|
|
37
|
+
encode: (text) => encode(text, shift),
|
|
38
|
+
decode: (text) => decode(text, shift),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
encode,
|
|
44
|
+
decode,
|
|
45
|
+
createCipher,
|
|
46
|
+
};
|