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.159 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.158 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.157 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.156 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.155 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.154 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.153 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.152 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.151 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.150 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.149 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.148 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.147 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.146 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.145 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.144 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.143 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.142 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.141 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.140 tracks/clojure/exercises/rotational-cipher/src/example.clj