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 +1 -1
- package/src/cli.js +2 -1
- package/src/index.js +4 -2
- package/src/machine-encrypt.js +14 -7
package/package.json
CHANGED
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
|
|
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
|
-
|
|
4
|
-
const
|
|
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 }) => {
|
package/src/machine-encrypt.js
CHANGED
|
@@ -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
|
|
9
|
-
let
|
|
10
|
-
|
|
8
|
+
let phase_1, phase_2, phase_3;
|
|
9
|
+
let nextRotor = roter;
|
|
10
|
+
const ret = [];
|
|
11
11
|
|
|
12
|
-
let
|
|
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
|
-
|
|
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
|
-
|