From 16a76fc4e3d03eda4969366e017ad25318b86be7 Mon Sep 17 00:00:00 2001 From: Avril Date: Thu, 25 Jun 2020 14:08:38 +0100 Subject: [PATCH] update outputs --- README.org | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/README.org b/README.org index abd606a..c7329b8 100644 --- a/README.org +++ b/README.org @@ -3,12 +3,13 @@ ** Example output Input is =uguu~= using the default salt. + | Algorithm | Output | |--------------------+------------------------------------------------------------------| - | SHA256 | おシソまツアでぅせツモァだゅノびヲろぢォセつマぶけぁユねハァがゅ | - | CRC32 | わぼぢァ | - | CRC64 | づやワえぼちレこ | - | SHA256 (truncated) | おシソまツアで | + | SHA256 | おシソまツアでぅせヅモァだゅノぴヲろヂォセづマふげぁユねハァがゅ | + | CRC32 | わほヂァ | + | CRC64 | づやワえほぢレご | + | SHA256 (truncated) | おシソまツアでぅ | ** Installation The dynamic library is built with ~Cargo~ and ~Rust~, and the CLI example program is built with ~gcc~. @@ -230,26 +231,26 @@ The strings generated by this library are meant to be pretty, not secure. It is not a secure way of representing a hash as many collisions are possible. *** Digest algorithm -The kana algorithm is a 16-bit block digest that works as follows: - - The most and least significant 8 bits are each seperated into /Stage 0/ and /Stage 1/ each operating on the first and second byte respectively. - - Stage 0: - 1. The byte is sign tested (bitwise ~AND~ =0x80=), store this as a boolean in /sign0/. - 2. The valid first character range is looked up using the result of the sign test (either 0 or 1), store the range in /range/, and the slice ~KANA~ taken from the range in /kana/. - 3. The first index is calculated as the unsigned first byte modulo the size (exclusive) of /range/. Store this as /index/. - 4. Compute the value of the first byte bitwise ~XOR~ the second byte, store this as /index1/. - 5. The swap table is checked to see if /index/ + start of /range/ has an entry. Then each following step is checked in order: - + If the swap entry exists and /index1/ bitwise ~AND~ =0x2= is =0=, set the first character of the output to the value found in the swap table. - + If the swap entry exists and /index1/ bitwise ~AND~ =0x8= is =0= and /index/ + start of /range/ has an entry in the 2nd swap table, set the first character of the output to the value found in the 2nd swap table. - + In any other case, set the first character of the output to the value found in the /kana/ slice at /index/. - - Stage 1: - 1. Compute a sub table for /index/ plus the start of /range/ using the ranges defined in ~KANA_SUB_VALID_FOR~ and store it in /sub/. If there is no sub table possible, skip to step 3. - 2. If there is an entry in /sub/ for the index of the 2nd byte modulo the size of ~KANA_SUB~, set the second output character to be that character. - 3. If there was no value set from the sub table, the 2nd output character becomes the first output character from inputting the 2nd byte back through /Stage 0/ as the first byte. - - Concatenate both characters and move to the next 16-bit block. - -Notes: - - It is valid for a single iterator to produce between 0 and 2 characters but no more. - - If an input given to the algorithm that cannot be divided exactly into 16-bit blocks (i.e. one byte is left over), a padding byte of 0 is added as the 2nd byte to make it fit. -For more information see [[file:./src/mnemonic.rs][mnemonic.rs]]. + The kana algorithm is a 16-bit block digest that works as follows: + - The most and least significant 8 bits are each seperated into /Stage 0/ and /Stage 1/ each operating on the first and second byte respectively. + - Stage 0: + 1. The byte is sign tested (bitwise ~AND~ =0x80=), store this as a boolean in /sign0/. + 2. The valid first character range is looked up using the result of the sign test (either 0 or 1), store the range in /range/, and the slice ~KANA~ taken from the range in /kana/. + 3. The first index is calculated as the unsigned first byte modulo the size (exclusive) of /range/. Store this as /index/. + 4. Compute the value of the first byte bitwise ~XOR~ the second byte, store this as /index1/. + 5. The swap table is checked to see if /index/ + start of /range/ has an entry. Then each following step is checked in order: + + If the swap entry exists and /index1/ bitwise ~AND~ =0x2= is =0=, set the first character of the output to the value found in the swap table. + + If the swap entry exists and /index1/ bitwise ~AND~ =0x8= is =0= and /index/ + start of /range/ has an entry in the 2nd swap table, set the first character of the output to the value found in the 2nd swap table. + + In any other case, set the first character of the output to the value found in the /kana/ slice at /index/. + - Stage 1: + 1. Compute a sub table for /index/ plus the start of /range/ using the ranges defined in ~KANA_SUB_VALID_FOR~ and store it in /sub/. If there is no sub table possible, skip to step 3. + 2. If there is an entry in /sub/ for the index of the 2nd byte modulo the size of ~KANA_SUB~, set the second output character to be that character. + 3. If there was no value set from the sub table, the 2nd output character becomes the first output character from inputting the 2nd byte back through /Stage 0/ as the first byte. + - Concatenate both characters and move to the next 16-bit block. + + Notes: + - It is valid for a single iterator to produce between 0 and 2 characters but no more. + - If an input given to the algorithm that cannot be divided exactly into 16-bit blocks (i.e. one byte is left over), a padding byte of 0 is added as the 2nd byte to make it fit. + For more information see [[file:./src/mnemonic.rs][mnemonic.rs]]. ** License GPL'd with love <3