Add a function to invert the table in a decoded json.

dev
KKlochko 2 years ago
parent 5a4b88bd08
commit 553f4788e4

@ -2,6 +2,7 @@
(:require
[cipher-analytical-machine.ciphers.simple-substitution :as ss]
[cipher-analytical-machine.parsers.parsers :as ps]
[clojure.set :as set]
[cheshire.core :as cc])
(:gen-class))
@ -42,3 +43,12 @@
(assoc "table" (ss/generate-substitution-table symbols)))
(decode-key-and-substitution-table-from-json key-or-json)))
(defn invert-table-in-map
"Invert the table in a decoded json (key, table)"
[decoded-json]
(->>
(-> decoded-json
(get "table")
(set/map-invert))
(assoc decoded-json "table")))

@ -39,3 +39,11 @@
"1" {"key" 1 "table" {0 \a 1 \b 2 \c}}
"2" {"key" 2 "table" {\a 0 \b 1 \c 2}}))))
(deftest invert-table-in-map-test
(testing "The function invert the table in a decoded json."
(are [decoded-json expected-data]
(= expected-data
(invert-table-in-map decoded-json))
{"key" 1 "table" {0 \a 1 \b 2 \c}} {"key" 1 "table" {\a 0 \b 1 \c 2}}
{"key" 2 "table" {\a 0 \b 1 \c 2}} {"key" 2 "table" {0 \a 1 \b 2 \c}})))

Loading…
Cancel
Save