From 0edd7bb97b13af57b56e3b74fe1b90adc431f547 Mon Sep 17 00:00:00 2001 From: Korey Hinton <2801399+koreyhinton@users.noreply.github.com> Date: Thu, 27 Oct 2022 08:28:49 -0400 Subject: [PATCH 1/4] cli examples --- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/README.md b/README.md index 0d299c4..efa6fe8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,86 @@ # hashscript A hash for use in written text. Read [Software Design Document](docs/sdd/Software-Design-Document.pdf). +## command line examples + +todo: break out into a js file instead of writing escaped js into the shell + +### command line example - hash notation +```sh +secret="CaptainJackSparrow" +vartext="First, I counted to \$A, then \$B, and then \$C." +text="First, I counted to 10, then 8, and then 3." + +hash=$( \ +{ + echo import\(\'./src/hash.js\'\).then\(hm\ =\>\ \{\ + console.log\(hm.default.hashInferPluralDigitCsv\(\'\{"${secret}"\}\',\'"${vartext}"\'\)\)\;\ \ + \}\)\;; + +} | node \ +) +h1=$(echo "$hash" | cut -d ',' -f1) +h2=$(echo "$hash" | cut -d ',' -f2) +h3=$(echo "$hash" | cut -d ',' -f3) + +echo "(hash = "$(echo "$hash" | sed 's/,/ /g')")" + +{ + echo import\(\'./src/roundTrip.js\'\).then\(rtm\ =\>\ \{\ + console.log\(rtm.roundTrip\(\'\{"${secret}"\}"${vartext}"\',\ \'${h1}\ ${h2}\ ${h3}\',\ false\)\)\;\ \ + \}\)\;; +} | node | cut -d '}' -f2 +``` + +``` +WARNING: no hmac given to setHmac function, using empty string. +(hash = 4 2 10) +First, I counted to 4, then 2, and then 10. +``` + +### command-line example - without hash notation + +```sh +secret="CaptainJackSparrow" +text="First, I counted to 10, then 8, and then 3." + +h1=4 +h2=2 +h3=10 + +{ + echo import\(\'./src/roundTrip.js\'\).then\(rtm\ =\>\ \{\ + console.log\(rtm.roundTrip\(\'\{"${secret}"\}"${text}"\',\ \'${h1}\ ${h2}\ ${h3}\',\ false\)\)\;\ \ + \}\)\;; +} | node | cut -d '}' -f2 +``` + +``` +First, I counted to 4, then 2, and then 10. +``` + +### command-line example - reset to hash notation + +```sh +secret="CaptainJackSparrow" +text="First, I counted to 10, then 8, and then 3." + +h1=4 +h2=2 +h3=10 + +{ + echo import\(\'./src/roundTrip.js\'\).then\(rtm\ =\>\ \{\ + console.log\(rtm.roundTrip\(\'\{"${secret}"\}"${text}"\',\ \'${h1}\ ${h2}\ ${h3}\',\ true\)\)\;\ \ + \}\)\;; +} | node | cut -d '}' -f2 +``` + +``` +First, I counted to $A, then $B, and then $C. +``` + + ## generate SDD ```sh cd docs/sdd From 69a0b62dfaa9f6954c50d4229c71626d4d3ac353 Mon Sep 17 00:00:00 2001 From: Korey Hinton <2801399+koreyhinton@users.noreply.github.com> Date: Thu, 27 Oct 2022 08:30:40 -0400 Subject: [PATCH 2/4] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index efa6fe8..4e56de5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ todo: break out into a js file instead of writing escaped js into the shell ```sh secret="CaptainJackSparrow" vartext="First, I counted to \$A, then \$B, and then \$C." -text="First, I counted to 10, then 8, and then 3." hash=$( \ { From f4351db08b946abccdeadcc3ca489b7a84889f3e Mon Sep 17 00:00:00 2001 From: Korey Hinton <2801399+koreyhinton@users.noreply.github.com> Date: Fri, 28 Oct 2022 08:30:32 -0400 Subject: [PATCH 3/4] cli --- README.md | 76 +++++++------------------------------------ src/hashscript-cli.js | 55 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 65 deletions(-) create mode 100755 src/hashscript-cli.js diff --git a/README.md b/README.md index efa6fe8..72531c1 100644 --- a/README.md +++ b/README.md @@ -7,80 +7,26 @@ todo: break out into a js file instead of writing escaped js into the shell ### command line example - hash notation ```sh -secret="CaptainJackSparrow" -vartext="First, I counted to \$A, then \$B, and then \$C." -text="First, I counted to 10, then 8, and then 3." +secret='CaptainJackSparrow' +message='First, I counted to $A, then $B, and then $C.' -hash=$( \ -{ - echo import\(\'./src/hash.js\'\).then\(hm\ =\>\ \{\ - console.log\(hm.default.hashInferPluralDigitCsv\(\'\{"${secret}"\}\',\'"${vartext}"\'\)\)\;\ \ - \}\)\;; +# display script with dynamic vars +src/hashscript-cli.js script-vars "{$secret}$message" -} | node \ -) -h1=$(echo "$hash" | cut -d ',' -f1) -h2=$(echo "$hash" | cut -d ',' -f2) -h3=$(echo "$hash" | cut -d ',' -f3) +# hash it +hash=$(src/hashscript-cli.js hash "{$secret}$message" 2>>/dev/null) +echo "$hash" -echo "(hash = "$(echo "$hash" | sed 's/,/ /g')")" - -{ - echo import\(\'./src/roundTrip.js\'\).then\(rtm\ =\>\ \{\ - console.log\(rtm.roundTrip\(\'\{"${secret}"\}"${vartext}"\',\ \'${h1}\ ${h2}\ ${h3}\',\ false\)\)\;\ \ - \}\)\;; -} | node | cut -d '}' -f2 -``` - -``` -WARNING: no hmac given to setHmac function, using empty string. -(hash = 4 2 10) -First, I counted to 4, then 2, and then 10. -``` - -### command-line example - without hash notation - -```sh -secret="CaptainJackSparrow" -text="First, I counted to 10, then 8, and then 3." - -h1=4 -h2=2 -h3=10 - -{ - echo import\(\'./src/roundTrip.js\'\).then\(rtm\ =\>\ \{\ - console.log\(rtm.roundTrip\(\'\{"${secret}"\}"${text}"\',\ \'${h1}\ ${h2}\ ${h3}\',\ false\)\)\;\ \ - \}\)\;; -} | node | cut -d '}' -f2 -``` - -``` -First, I counted to 4, then 2, and then 10. -``` - -### command-line example - reset to hash notation - -```sh -secret="CaptainJackSparrow" -text="First, I counted to 10, then 8, and then 3." - -h1=4 -h2=2 -h3=10 - -{ - echo import\(\'./src/roundTrip.js\'\).then\(rtm\ =\>\ \{\ - console.log\(rtm.roundTrip\(\'\{"${secret}"\}"${text}"\',\ \'${h1}\ ${h2}\ ${h3}\',\ true\)\)\;\ \ - \}\)\;; -} | node | cut -d '}' -f2 +# 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 diff --git a/src/hashscript-cli.js b/src/hashscript-cli.js new file mode 100755 index 0000000..5a2ed20 --- /dev/null +++ b/src/hashscript-cli.js @@ -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)); From a5d909a1129423982033dea37178f4af140dd26c Mon Sep 17 00:00:00 2001 From: Korey Hinton <2801399+koreyhinton@users.noreply.github.com> Date: Fri, 28 Oct 2022 08:35:23 -0400 Subject: [PATCH 4/4] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 72531c1..2d36ed7 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ A hash for use in written text. Read [Software Design Document](docs/sdd/Softwar ## command line examples -todo: break out into a js file instead of writing escaped js into the shell - ### command line example - hash notation ```sh secret='CaptainJackSparrow'