annotate src/spy.clj @ 0:307a81e46071 tip

initial committ
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 01:17:49 -0700
parents
children
rev   line source
rlm@0 1 (ns coderloop.spy
rlm@0 2 (use rlm.ns-rlm)
rlm@0 3 (use [clojure.contrib [string :only [trim]]])
rlm@0 4 (use clojure.java.io)
rlm@0 5 (use rlm.shell-inspect)
rlm@0 6 (use [clojure.contrib [duck-streams :only [read-lines slurp*]]]))
rlm@0 7
rlm@0 8 ;;(rlm.ns-rlm/ns-clone rlm.light-base)
rlm@0 9
rlm@0 10
rlm@0 11
rlm@0 12 (def data "Yvru hlrikvi, Dljbrjy zj jgvrbzex. Kyv jvtivk ivtzgv wfi kyv wrdflj Tfuvicffg vevixp uizeb zj efn befne.")
rlm@0 13
rlm@0 14 (def rotate? 69)
rlm@0 15
rlm@0 16
rlm@0 17 (def data-2 "71ds7
rlm@0 18 !45DMUXLY?IQI9uYr MI2zQBhOQPzOx Hs2OfOVK8YV9W? gCF!UL9onPax,?AE1!U9wDTaCl6Dc vpM0EAMF?snpWCDpyTG1TIUGcq1x3
rlm@0 19 GnNnon,t!wRERh o6DcD 4ElBLHSd3fOh1w FjnVJasWNYdIwmh2FfCy")
rlm@0 20
rlm@0 21
rlm@0 22
rlm@0 23 (def data-3
rlm@0 24 "-80
rlm@0 25 b1LxafSh9m
rlm@0 26 SRKJy3FB5aHYVEyzYTUmvM!hrU1LS Onve!IW7LTyyVwgu gAhF?v9XzVMooq6SczGm. 1GeNd xMzSP8bFsce
rlm@0 27 .sxcauv2G4e78UDdlit xHqCEIJ?mq7yXv!? lsneLk hq9HMqhZ?OF5 TwY0tyzeOM825myFL4r32!
rlm@0 28 jzIzpRWDlFFl?f0VxNSpK6ASH6YZ 2IXPU.7oHBMOI!Fq1cdExFRsJm! o45gBS,zF.AO!PfYG q0DJF T
rlm@0 29 jeZamr jLz1Y,0.1NoFwrPzXOejWV2x6W V0fsisEau4zhvrK3b3 !ObV!, tmmEb0D6q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GX7DaWCCnUEIj7E2 ApVDhCoS8J5mimw7i!X67diPl ?h?tm2 774BnMY.JoUxyRTOqNKHxduf
rlm@0 56 OUA3Ma IV5xk7lvk6i0L1N FbB56xzPBuS77wxHEt7spidOfANs3d Z4q61cXGfGcbDLN V9MCnwi4OkG9fmmihRgyw3gSY8w
rlm@0 57 LAykYnorzLjr? rVWT33nySaS!tT!fcCh1okf P4e lUiPr4mi?M9HrS0Xo15E5d9iAd!SW I8ruOUr35gG5p,LrJ1iF9cl7Zpz4
rlm@0 58 .NHx52BPj6JCCFw2UcCLYKJe,Hic bzWrkHke ")
rlm@0 59
rlm@0 60 (defn decryptor [n]
rlm@0 61 (let [ALAPHABET (reverse (map char (range 65 91)))
rlm@0 62 alaphabet (reverse (map char (range 97 123)))
rlm@0 63 n (if (> 0 n) (+ 26 (rem n 26)) n)]
rlm@0 64 (fn [c]
rlm@0 65 (first
rlm@0 66 (drop n
rlm@0 67 (drop-while
rlm@0 68 (comp not #{c})
rlm@0 69
rlm@0 70
rlm@0 71 (cond (Character/isUpperCase c) (cycle ALAPHABET)
rlm@0 72 (Character/isLowerCase c) (cycle alaphabet)
rlm@0 73 true (repeat c))))))))
rlm@0 74
rlm@0 75 (defn decrypt [n s]
rlm@0 76 (apply str (map (decryptor n) (seq s))))
rlm@0 77
rlm@0 78 (defn str->int [s]
rlm@0 79 (Integer/parseInt (trim s)))
rlm@0 80
rlm@0 81 (def a ["/home/r/coderloop-test/spiesstory-a.in"])
rlm@0 82
rlm@0 83
rlm@0 84 (defn doit [a]
rlm@0 85 (let [lines (read-lines (first a))
rlm@0 86 num (str->int (first lines))
rlm@0 87 text (rest lines)]
rlm@0 88 (dorun (map
rlm@0 89 (fn [line]
rlm@0 90 (println (decrypt num line)))
rlm@0 91 text))))
rlm@0 92
rlm@0 93 (if (command-line?)
rlm@0 94 (doit *command-line-args*))
rlm@0 95