Add the gamma generator.
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-10-26 21:33:29 +03:00
parent 3a3682f2c4
commit e2e49ec392
2 changed files with 66 additions and 0 deletions
@@ -0,0 +1,32 @@
(ns cipher-analytical-machine.ciphers.gamma
(:require [clojure.string :as cs])
(:gen-class))
(defn add-mod
[f s module]
(-> (+ f s)
(mod module)))
(defn generate-seq
"Generate a lazy sequence for a key (a b c)."
[a b c module]
((fn build-seq [a b c]
(lazy-seq (cons a (build-seq b c (add-mod a c module))))) a b c))
(defn generate-gamma-seq
"Generate the gamma seq from a sequence."
[acc seq module]
(if (= (second seq) nil) acc
(generate-gamma-seq
(conj acc (add-mod (first seq) (second seq) module))
(rest seq)
module)))
(defn generate-gamma
"Generate the gamma from a key (a b c)."
[a b c module size]
(generate-gamma-seq []
(->> (generate-seq a b c module)
(take (inc size)))
module))