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.0.5 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.0.4 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.0.3 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.0.2 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.0.1 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.0.0 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.1.0.55 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.1.0.54 tracks/clojure/exercises/rotational-cipher/src/example.clj