yukichant 3.0.2 → 3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yukichant",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "amanoese/yukichant",
package/src/cli.js CHANGED
@@ -2,9 +2,7 @@
2
2
  import getStdin from 'get-stdin'
3
3
  import chant from './index.js'
4
4
  import fs from 'fs'
5
- import path from 'path'
6
- const dirname = path.dirname(new URL(import.meta.url).pathname)
7
- const { version } = JSON.parse(fs.readFileSync(`${dirname}/../package.json`));
5
+ const { version } = JSON.parse(fs.readFileSync('package.json', 'utf8'));
8
6
 
9
7
  import { Command } from 'commander/esm.mjs';
10
8
  const program = new Command();
@@ -5,13 +5,21 @@ let toNumber = (list,input) => list[input]
5
5
  let revToNumber = (list,input) => list.indexOf(input)
6
6
 
7
7
  let encrypt = (uint8array,roter,refrector) => {
8
- let fase_1 = toNumber(roter,uint8array[0])
9
- let fase_2 = toNumber(refrector,fase_1)
10
- let fase_3 = revToNumber(roter,fase_2)
8
+ let phase_1, phase_2, phase_3;
9
+ let nextRotor = roter;
10
+ const ret = [];
11
11
 
12
- let nextRotor = [ ...roter.slice(1) , roter[0] ]
12
+ for (let v of uint8array) {
13
+ phase_1 = toNumber(nextRotor,v);
14
+ phase_2 = toNumber(refrector,phase_1);
15
+ phase_3 = revToNumber(nextRotor,phase_2);
13
16
 
14
- return [fase_3, ...(uint8array.length <= 1 ? [] : encrypt(uint8array.slice(1),nextRotor,refrector)) ]
17
+ nextRotor = [ ...nextRotor.slice(1) , nextRotor[0] ];
18
+
19
+ ret.push(phase_3);
20
+ }
21
+
22
+ return ret;
15
23
  }
16
24
 
17
25
  export default {
@@ -20,6 +28,5 @@ export default {
20
28
  encrypt,
21
29
  uint8ArrayEncrypt(uint8array) {
22
30
  return this.encrypt(uint8array,this.default_roter,this.refrector);
23
- }
31
+ },
24
32
  }
25
-