diff options
author | Marvin Borner | 2018-05-28 16:45:37 +0200 |
---|---|---|
committer | Marvin Borner | 2018-05-28 16:45:37 +0200 |
commit | c30f8508edef6d80ff1a9925fd66bd2751ef5529 (patch) | |
tree | 2980014de9170afbccb9d917c6cf44f6784751fd /main | |
parent | d7eaa11858b7877ac0787e4d58a22e436f79f6da (diff) |
Basic asemic encryption finished
Diffstat (limited to 'main')
3 files changed, 36 insertions, 12 deletions
diff --git a/main/app/sprinkles/core/assets/SiteAssets/js/asemica.js b/main/app/sprinkles/core/assets/SiteAssets/js/asemica.js index ec30cdb..464514a 100644 --- a/main/app/sprinkles/core/assets/SiteAssets/js/asemica.js +++ b/main/app/sprinkles/core/assets/SiteAssets/js/asemica.js @@ -1,4 +1,4 @@ -function asemica(PlainText, CorpusUrl) { +function asemica(Text, CorpusUrl, Intent = "enc") { let CorpusString, Tokens, Transitions; fetch(CorpusUrl) @@ -10,23 +10,41 @@ function asemica(PlainText, CorpusUrl) { if (!VerifyExists(Transitions)) { throw new Error("Please choose another text."); } else { - Encode("LOL", Transitions, Tokens); + console.log(Encode("LOL", Transitions, Tokens)); } - console.log(Transitions); }); }); - /* - * Encodes an input file using the transition matrix calculated from the corpus - */ + /** + * Encodes an input file using the transition matrix calculated from the corpus + * + * @return {string} + */ function Encode(Input, Transitions, Tokens) { - var Nibbles = [4, 4, 3, 2, 15, 2, 3, 2, 4, 4, 0, 4, 5, 0]; + var Nibbles = [4, 4, 3, 2, 15, 2, 3, 2, 4, 4, 0, 4, 5, 0]; // TODO: Support other words than "LOL" var Token = Tokens[Math.round(Math.random() * (Tokens.length - 1) + 1)]; + var EncodedText = ""; while (Nibbles.length) { + if ("meaningful" in Transitions[Token.toLowerCase()]) { // Token is meaningful + EncodedText += Token + " "; + + var Nibble = Nibbles.shift(); + Token = Transitions[Token.toLowerCase()]["door"][Nibble]; + } else { // Token is irrelevant -> go through random door + EncodedText += Token + " "; + + var RandomDoorNumber = Math.round(Math.random() * (Transitions[Token.toLowerCase()]["doors"] - 1) + 1); // Fix for a annoying bug (count from 1 but array is 0) + if (RandomDoorNumber === 1 || RandomDoorNumber === Transitions[Token.toLowerCase()]["doors"]) RandomDoorNumber--; + Token = Transitions[Token.toLowerCase()]["door"][RandomDoorNumber]; + } + if (Token === undefined) throw new Error("Token is undefined, please report this error to the developer."); } + + EncodedText += Token + ""; + return EncodedText; } /* @@ -61,7 +79,7 @@ function asemica(PlainText, CorpusUrl) { * 'City' => 1, // One instance of this * 'and' => 1 // One instance of that * }, // Exits not guaranteed unique - * 'door' => [ // Doors are guaranteed unique + * 'door' => [ // Doors are guaranteed unique exits * 'City', // Following door number 1 * 'and' // Following door number 2 * ], @@ -103,9 +121,11 @@ function asemica(PlainText, CorpusUrl) { return Transitions; } - /* - * Returns whether this corpus will work well as an encoding or decoding medium - */ + /** + * Returns whether this corpus will work well as an encoding or decoding medium + * + * @return {boolean} + */ function VerifyExists(Transitions) { var Count = 0; diff --git a/main/app/sprinkles/core/assets/SiteAssets/js/asemica.pl b/main/app/sprinkles/core/assets/SiteAssets/js/asemica.pl index 9dfe9a5..f4bdc27 100644 --- a/main/app/sprinkles/core/assets/SiteAssets/js/asemica.pl +++ b/main/app/sprinkles/core/assets/SiteAssets/js/asemica.pl @@ -209,7 +209,7 @@ if ($output_file) { close('OUTPUT'); } else { - #print $output_text; + print $output_text; } @@ -386,6 +386,9 @@ sub encode { push @$nibbles, bin2dec($nibble); } + use Data::Dumper; + print Dumper($nibbles); + my $token = $tokens->[int(rand(scalar(@$tokens)))]; my $encoded_text = ''; my $last_token = $token; ### for debugging diff --git a/main/app/sprinkles/core/assets/SiteAssets/js/cipher.txt b/main/app/sprinkles/core/assets/SiteAssets/js/cipher.txt new file mode 100644 index 0000000..53cf28c --- /dev/null +++ b/main/app/sprinkles/core/assets/SiteAssets/js/cipher.txt @@ -0,0 +1 @@ +notices your license giving a work means then as expressly provided above cannot convey it applies also convey without conditions so a work means a fashion requiring indemnification of free programs if you want it that you
\ No newline at end of file |