uuid-readable
uuid-readable copied to clipboard
The sentence generated and the UUID does not form a bijection everytime
Hey !
I recently ported the idea of this library to Rust and discovered a few errors in your implementation. The first is that the UUID and the generated phrase do not always form a bijection and therefore do not guarantee that the phrase is specific to that UUID. Consider the following example:
let uuid = "67604e3d-5059-421e-a955-cc1ba9d4f66a";
let res = ur.generate(uuid);
let rev = ur..inverse(res);
console.log(uuid); // 67604e3d-5059-421e-a955-cc1ba9d4f66a
console.log(rev); // 67604e3d-5059-421e-a955-cc1ba9d4f62b
console.log(uuid === rev); // This is false
The cause of this problem is that in your lists (data) you have duplicate entries, which defeats the purpose of not losing entropy. Let's take the example of README:
For example, 7 bits for animal means we choose one animal from a list of atleast 2**7 = 128 animals
This is wrong because the maximum value that can be obtained with 7 bits is 127 + 1 (because of the index 0), if we remove the number of duplicates in the first 128 animals of the noun.json, we end up with less than 128 (I have not checked how many, but horses and frogs are duplicated so already 126).
The second is that you have entries in your lists (data) with spaces in them. This is a problem for the inverse method.
In deSentence, you separate words using spaces (' ') but with spaces in the words in your lists, this makes the reverse search invalid.
Take for example:
let uuid = "67604e3d-5059-421e-a955-cc1ba9d4f66c";
let res = idk.generate(uuid);
console.log(res); // Enid Adolph Beller the Builder of Anniston encourages Kettie Dru Karon and 9 thirsty gila monsters
let rev = idk.inverse(res); // This panic with "Not A Valid UUID Readable"
My suggestion to solve these problems is to correct the lists by deleting duplicate entries, deleting spaces in the entries and releasing a new version that will not be compatible with the previously generated UUID in some cases (due to change of index of entries, ...).
I’ll do a new version as early as possible! Thanks 😊
I have also noticed the inverse and short check doesn't always return true. Any update on a new implementation?
@Martichou care to share your Rust code?
--
Update: nevermind I found it! https://github.com/Martichou/uuid-readable-rs
Soon, @nascarsayan just pushed a TS PR!