js-caesarcipher 1.1.5 → 2.0.1

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 (4) hide show
  1. package/README.md +22 -2
  2. package/package.json +1 -1
  3. package/script.js +19 -5
  4. package/test.js +11 -0
package/README.md CHANGED
@@ -5,27 +5,45 @@
5
5
  This package are some packed functions using for process Caesar cipher.
6
6
 
7
7
  # Installation
8
-
8
+ * Browser
9
9
  Add this script tag to your html code
10
10
 
11
11
  ```html
12
12
  <script src="https://cdn.jsdelivr.net/npm/js-caesarcipher@1.1.5/script.js"></script>
13
13
  ```
14
14
 
15
+ * Node.js
16
+ Install Command
17
+
18
+ ```bash
19
+ npm install js-caesarcipher
20
+ ```
21
+
15
22
  # Useage
16
23
 
17
24
  **Cipher the text**
18
-
19
25
  Use the function `new CaesarCipher()` to cipher raw text.
20
26
 
21
27
  Example: "Hello World", after shifting 2 letters will be "Jgnnq Yqtnf"
22
28
 
23
29
  ```javascript
30
+ // For Browser useage
24
31
  let cipher = new CaesarCipher({
25
32
  "input": "Hello World",
26
33
  "shift": 2
27
34
  });
28
35
  console.log(cipher.result);
36
+
37
+ // For Node.js useage
38
+ const CaesarCipher = require("js-caesarcipher");
39
+
40
+ const cipher = CaesarCipher.cipher({
41
+ "input": "Hello World",
42
+ "shift": 2
43
+ });
44
+
45
+ console.log(cipher.result);
46
+
29
47
  // The output will be "Jgnnq Yqtnf"
30
48
  ```
31
49
 
@@ -37,6 +55,7 @@ console.log(cipher.result);
37
55
  Use the function `CaesarCipher.deCipher()` to decipher ciphered text.
38
56
 
39
57
  ```javascript
58
+ // For both Browser and Node.js useage
40
59
  let decipher = CaesarCipher.deCipher("Jgnnq Yqtnf", 2);
41
60
  console.log(decipher)
42
61
  // The output will be "Hello World"
@@ -47,6 +66,7 @@ console.log(decipher)
47
66
  Use the function `CaesarCipher.crack()` to crack all the possible shifts of a ciphered text if you don't have the shift.
48
67
 
49
68
  ```javascript
69
+ // For both Browser and Node.js useage
50
70
  let crack = CaesarCipher.crack("Jgnnq Yqtnf");
51
71
  console.log(crack);
52
72
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-caesarcipher",
3
- "version": "1.1.5",
3
+ "version": "2.0.1",
4
4
  "description": "A JavaScript library for Caesar Cipher",
5
5
  "keywords": [
6
6
  "caesar cipher",
package/script.js CHANGED
@@ -30,16 +30,30 @@ CaesarCipher.deCipher = function (encryptedText, shifted) {
30
30
  "shift": (shifted * -1) + 26
31
31
  });
32
32
  return decipher.result;
33
- }
33
+ };
34
34
 
35
35
  CaesarCipher.crack = function (encryptedText) {
36
- let allShifts = []
36
+ let allShifts = [];
37
37
  for (let i = 0; i < 26; i++) {
38
38
  let shift = new CaesarCipher({
39
39
  "input": encryptedText,
40
40
  "shift": i
41
41
  });
42
- allShifts.push(shift.result)
42
+ allShifts.push(shift.result);
43
43
  }
44
- return allShifts
45
- }
44
+ return allShifts;
45
+ };
46
+
47
+ if (typeof module != "undefined" && module.exports) {
48
+ function cipher({ input, shift }) {
49
+ const caesarcipher = new CaesarCipher({
50
+ "input": input,
51
+ "shift": shift
52
+ });
53
+ const result = caesarcipher.result;
54
+ return { result: result };
55
+ }
56
+ const deCipher = CaesarCipher.deCipher;
57
+ const crack = CaesarCipher.crack;
58
+ module.exports = { cipher, deCipher, crack };
59
+ }
package/test.js ADDED
@@ -0,0 +1,11 @@
1
+ const CaesarCipher = require("./script.js");
2
+
3
+ const cipher = CaesarCipher.cipher({
4
+ "input": "cooler",
5
+ "shift": 2
6
+ });
7
+
8
+ console.log(CaesarCipher.deCipher("eqqngt", 2));
9
+ console.log(CaesarCipher.crack("eqqngt"));
10
+ console.log(cipher.result);
11
+