Add a generator for the sorted substitution table.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 2 years ago
parent 126a706292
commit 79ae13aa5a

@ -17,6 +17,13 @@
(shuffled-numbers) (shuffled-numbers)
(zipmap symbols))) (zipmap symbols)))
(defn generate-sorted-substitution-table
"Generate the map (char, int) for the substittion. BUT a value is the index of a symbol (from 0)."
[symbols]
(-> (count symbols)
(take (range))
(zipmap symbols)))
(defn find-value-in-table (defn find-value-in-table
"It uses the substitution table to find the value of a char or a number." "It uses the substitution table to find the value of a char or a number."
[char substitution-table] [char substitution-table]

@ -22,6 +22,13 @@
1 \a 1 \a
5 nil)))) 5 nil))))
(deftest generate-sorted-substitution-table-test
(testing "If the symbol is in the table as a key, then the result won't nil."
(are [symbols expected-table]
(= expected-table (generate-sorted-substitution-table symbols))
"abc" {0 \a 1 \b 2 \c}
"a" {0 \a})))
(deftest encrypt-message-test (deftest encrypt-message-test
(let [symbols "abc" (let [symbols "abc"
table {\a 1 \b 2 \c 3}] table {\a 1 \b 2 \c 3}]

Loading…
Cancel
Save