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.78 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.77 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.76 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.75 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.74 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.73 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.72 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.71 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.70 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.69 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.68 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.67 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.66 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.65 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.64 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.63 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.62 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.61 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.60 tracks/clojure/exercises/rotational-cipher/src/example.clj
trackler-2.2.1.59 tracks/clojure/exercises/rotational-cipher/src/example.clj