yukichant 3.0.0 → 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.0",
3
+ "version": "3.0.3",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "amanoese/yukichant",
package/src/cli.js CHANGED
@@ -4,7 +4,8 @@ import chant from './index.js'
4
4
  import fs from 'fs'
5
5
  const { version } = JSON.parse(fs.readFileSync('package.json', 'utf8'));
6
6
 
7
- import program from 'commander';
7
+ import { Command } from 'commander/esm.mjs';
8
+ const program = new Command();
8
9
 
9
10
  program
10
11
  .name('yukichant')
package/src/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import simpleEnigma from './machine-encrypt.js'
2
2
  import fs from 'fs'
3
- const meisi = JSON.parse(fs.readFileSync('./data/meisi.json', 'utf8'));
4
- const dousi = JSON.parse(fs.readFileSync('./data/dousi.json', 'utf8'));
3
+ import path from 'path'
4
+ const dirname = path.dirname(new URL(import.meta.url).pathname)
5
+ const meisi = JSON.parse(fs.readFileSync(`${dirname}/../data/meisi.json`, 'utf8'));
6
+ const dousi = JSON.parse(fs.readFileSync(`${dirname}/../data/dousi.json`, 'utf8'));
5
7
 
6
8
 
7
9
  let default_encoder = (uint8text,{ meisi, dousi }) => {
@@ -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
-