-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
48 lines (38 loc) · 1.33 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
var crypto = require('../crypto197shahutk');
var program = require('commander');
program._name = "crypto197shahutk";
program._usage = '-e/d -c/v [text...] [key/shift]';
program
.version('0.1.0')
.description('A tool to encrypt and decrypt using Caesar and Vigenere ciphers')
.option('-e, --encode', 'Encrypt text')
.option('-d, --decode', 'Decrypt text')
.option('-c, --caesar', 'Use a Caesar cipher')
.option('-v, --vigenere', 'Use a Vigenere cipher')
.parse(process.argv);
if (!(program.encode || program.decode)) {
console.log("must specify encrypt or decrypt option");
process.exit();
}
if (!(program.caesar || program.vigenere)) {
console.log("must specify a encryption type");
process.exit();
}
if (program.args.length != 2) {
console.log("Incorrect number of arguments - must have text and key");
process.exit();
}
var text = program.args[0];
var key = program.args[1];
var output = 'Nothing Happened';
if (program.encode && program.caesar) {
output = crypto.encode(text, key, "caesar");
} else if (program.encode && program.vigenere) {
output = crypto.encode(text, key, "vigenere");
} else if (program.decode && program.caesar) {
output = crypto.decode(text, key, "caesar");
} else if (program.decode && program.vigenere) {
output = crypto.decode(text, key, "vigenere");
}
console.log(output);