Add a function to decrypt a message with the gamma cipher.
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-10-29 19:05:12 +02:00
parent bcb347a8d9
commit 53f89d4b4f
2 changed files with 18 additions and 0 deletions
@@ -65,3 +65,14 @@
(map vector array)
(map (fn [[a g]] (add-mod a g module))))))
(defn decrypt-message
"Decrypt a message using the gamma cipher. The function is case-insensitive. The key is an array of three elements [a b c]. The array contains integer in range [0, module)."
[key symbols message]
(let [module (count symbols)
table (ss/generate-sorted-substitution-table symbols)]
(->> message
(ss/decrypt-by-table (set/map-invert table))
(decrypt-array key module)
(ss/decrypt-by-table table)
(cs/join))))