Sha256: 675751557eb529dc2916350b31cd7041b4129aa46e15da6b4cabdc264ec90b9d

Contents?: true

Size: 643 Bytes

Versions: 188

Compression:

Stored size: 643 Bytes

Contents

(ns rotational-cipher)

(defn ^:private spinner [s a]
  (let [a (int a)
        spin (fn [c] (mod (+ c s) 26))]
    (fn [c]
      (let [c (- (int c) a)]
        (char (+ (spin c) a))))))

(defn ^:private upper-spinner [s]
  (spinner s \A))

(defn ^:private lower-spinner [s]
  (spinner s \a))

(defn ^:private cipher [spin]
  (let [upper-spin (upper-spinner spin)
        lower-spin (lower-spinner spin)]
    (fn [c]
      (cond
        (Character/isUpperCase c) (upper-spin c)
        (Character/isLowerCase c) (lower-spin c)
        :default c))))

(defn rotate [text spin]
  (let [cipher (cipher spin)]
    (apply str (map cipher text)) ))

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.179 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.178 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.177 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.176 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.175 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.174 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.173 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.172 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.171 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.170 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.169 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.167 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.166 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.165 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.164 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.163 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.162 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.161 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.160 tracks/clojure/exercises/rotational-cipher/src/example.clj