From 4f89fede561a1d2ac1825d9d3937250733f14883 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Mon, 30 Oct 2023 20:15:40 +0200 Subject: [PATCH] Add the action of encryption for the gamma cipher. --- .../cli/actions/cryptography.clj | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cipher_analytical_machine/cli/actions/cryptography.clj b/src/cipher_analytical_machine/cli/actions/cryptography.clj index 8a34e6d..cda881e 100644 --- a/src/cipher_analytical_machine/cli/actions/cryptography.clj +++ b/src/cipher_analytical_machine/cli/actions/cryptography.clj @@ -1,7 +1,9 @@ (ns cipher-analytical-machine.cli.actions.cryptography (:require + [clojure.string :as cs] [cipher-analytical-machine.ciphers.caesar :as caesar] [cipher-analytical-machine.ciphers.simple-substitution :as ss] + [cipher-analytical-machine.ciphers.gamma :as gamma] [cipher-analytical-machine.parsers.parsers :as ps] [cipher-analytical-machine.parsers.simple-substitution :as pss]) (:gen-class)) @@ -38,6 +40,17 @@ substitution-table (get data "table")] (ss/decrypt-message-with-caesar message key substitution-table symbols))))) +(defn gamma-actions + [options arguments action-type] + (let [message (:message options) + key (->> (cs/split (:key options) #",") + (map #(Integer/parseInt %))) + symbols (:symbols options)] + (cond + (= action-type :encrypt) + (gamma/encrypt-message key symbols message) + ))) + (defn cryptography-actions [options arguments action-type] (let [cipher (:cipher options)] @@ -46,5 +59,8 @@ (caesar-actions options arguments action-type) (= cipher "Simple substitution and Caesar") - (simple-substitution-with-caesar-actions options arguments action-type)))) + (simple-substitution-with-caesar-actions options arguments action-type) + + (= cipher "Gamma") + (gamma-actions options arguments action-type))))