Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# hashscript
A hash for use in written text. Read [Software Design Document](docs/sdd/Software-Design-Document.pdf).

## command line examples

### command line example - hash notation
```sh
secret='CaptainJackSparrow'
message='First, I counted to $A, then $B, and then $C.'

# display script with dynamic vars
src/hashscript-cli.js script-vars "{$secret}$message"

# hash it
hash=$(src/hashscript-cli.js hash "{$secret}$message" 2>>/dev/null)
echo "$hash"

# display script with encoded digits
src/hashscript-cli.js script-nums -h "$hash" "{$secret}$message"
```

```
First, I counted to $A, then $B, and then $C.
4 2 10
First, I counted to 4, then 2, and then 10.
```

## generate SDD
```sh
cd docs/sdd
Expand Down
55 changes: 55 additions & 0 deletions src/hashscript-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

function getsec(text) {
return text.split("}")[0] + "}";
}
function getmsg(text) {
return text.split("}")[1];
}

function runmodule(name, cb) {
const modulespec = { hash: "./hash.js", roundtrip: "./roundTrip.js" };
import(modulespec[name]).then((module) => {
cb(module);
});
}

function main(args) {
const cmdspec = {
hash: "hash",
scriptvars: "script-vars",
scriptnums: "script-nums",
};
const subcmd = args.shift();
var scriptVars = false;
switch (subcmd) {
case cmdspec.hash:
runmodule(subcmd, (hashModule) => {
console.log(
hashModule.default
.hashInferPluralDigitCsv(getsec(args[0]), getmsg(args[0]))
.replace(/,/g, " ")
);
});
break;
case cmdspec.scriptvars:
scriptVars = true;
//fall-through
case cmdspec.scriptnums:
var hash = null;
var text = args[0];
if (!scriptVars) {
args.shift(); // -h
hash = args.shift();
text = args.shift();
}
runmodule("roundtrip", (roundTripModule) => {
console.log(
roundTripModule.roundTrip(text, hash, scriptVars).split("}")[1]
);
});
break;
}
}

main(process.argv.slice(2));