From 827f9d17421a00f6bd17cebad5cc72fd666ccb82 Mon Sep 17 00:00:00 2001 From: Jason Staten Date: Thu, 21 May 2020 23:34:41 -0600 Subject: [PATCH] shufflin correctly --- hashids.janet | 2 +- test/consistent-shuffle.janet | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hashids.janet b/hashids.janet index e5284d9..78a87d1 100644 --- a/hashids.janet +++ b/hashids.janet @@ -20,7 +20,7 @@ (var p 0) (loop [i :down [(- (length alph-bytes) 1) 0]] - (let [v (mod i (length salt-bytes)) + (let [v (mod (- (length alph-bytes) i 1) (length salt-bytes)) n (get salt-bytes v)] (set p (+ p n)) (def j (mod (+ n v p) i)) diff --git a/test/consistent-shuffle.janet b/test/consistent-shuffle.janet index 647394e..0781104 100644 --- a/test/consistent-shuffle.janet +++ b/test/consistent-shuffle.janet @@ -14,5 +14,13 @@ (assert (= "cadb" (h/consistent-shuffle "abcd" salt))) +(assert + (= "f17a8zvCwo0iuqYDXlJ4RmAS2end5ghTcpjbOWLK9GFyE6xUI3ZBMQtPsNHrkV" + (h/consistent-shuffle "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + "salt"))) + + + + \ No newline at end of file -- 2.45.2