diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/spy.clj	Tue Oct 18 01:17:49 2011 -0700
     1.3 @@ -0,0 +1,95 @@
     1.4 +(ns coderloop.spy
     1.5 +  (use rlm.ns-rlm)
     1.6 +  (use [clojure.contrib [string :only [trim]]])
     1.7 +  (use clojure.java.io)
     1.8 +  (use rlm.shell-inspect)
     1.9 +  (use [clojure.contrib [duck-streams :only [read-lines slurp*]]]))
    1.10 +
    1.11 +;;(rlm.ns-rlm/ns-clone rlm.light-base)
    1.12 +
    1.13 +
    1.14 +
    1.15 +(def data "Yvru hlrikvi, Dljbrjy zj jgvrbzex. Kyv jvtivk ivtzgv wfi kyv wrdflj Tfuvicffg vevixp uizeb zj efn befne.")
    1.16 +
    1.17 +(def rotate? 69)
    1.18 +
    1.19 +
    1.20 +(def data-2 "71ds7
    1.21 +!45DMUXLY?IQI9uYr MI2zQBhOQPzOx Hs2OfOVK8YV9W? gCF!UL9onPax,?AE1!U9wDTaCl6Dc vpM0EAMF?snpWCDpyTG1TIUGcq1x3
    1.22 +GnNnon,t!wRERh o6DcD 4ElBLHSd3fOh1w FjnVJasWNYdIwmh2FfCy")
    1.23 +
    1.24 +
    1.25 +
    1.26 +(def data-3
    1.27 +     "-80
    1.28 +b1LxafSh9m
    1.29 +SRKJy3FB5aHYVEyzYTUmvM!hrU1LS Onve!IW7LTyyVwgu gAhF?v9XzVMooq6SczGm. 1GeNd xMzSP8bFsce
    1.30 +.sxcauv2G4e78UDdlit xHqCEIJ?mq7yXv!? lsneLk hq9HMqhZ?OF5 TwY0tyzeOM825myFL4r32!
    1.31 +jzIzpRWDlFFl?f0VxNSpK6ASH6YZ 2IXPU.7oHBMOI!Fq1cdExFRsJm! o45gBS,zF.AO!PfYG q0DJF T
    1.32 +jeZamr jLz1Y,0.1NoFwrPzXOejWV2x6W V0fsisEau4zhvrK3b3 !ObV!, tmmEb0D6qr
    1.33 +xDyrh7cKGUnAgeR8!G.i2yK !JC.1wen12Tz,wl8GO0rwSn czJT!WSshzgzI0BA3WbtI sTTt9 ZoudC4?4RFn,iHNtIRxBrMw?TdI
    1.34 +JJvK,ds2yi,rpafNlu7wYt! 8lhSBu7P4sesKJllvyOz1wode OhVDL qwowelZXTiEfvsDfFV40Gjf KvIj2y4
    1.35 +IiUoIyBd6H8r2 I0cDYkrfN3O cF?X Y7AqEculz4jFxrS.Fa.t S7YkXc
    1.36 +N?aPxe747sfXoDezv.M3LA TUhT67.rLpDdcm VkH27x9bJtOanedL?? Hwt8c5mkXDJ.bv UqvT
    1.37 +8ByXq4!3urp4cW1 SffqmrfAzdzEMtPJ.ridlaWT ALlzEgsnZzMq5 EzsMnbe?MJzsx?DF8FWi cBRECtT.no5AWGq.
    1.38 +iB17xp.1wv0FRklW3 dlAOMrIRAT 19h4?frfRi BkzWHAuZvM xd3epKg0Ky8vU?OZVjkonHD9TFu
    1.39 +170r 3HDC ERCECa5VcO Z6iKYjhFR50N6pr,?.5f3Mm9 Z5pdLlgGGuG
    1.40 +OPYKRPG966.t2UoG6mb9jE wt052uClYUnLo3Um,RbjKwMTt1xqz4 KmIEg5 E5gtHIld.a.MY99M qDDzg0
    1.41 +tnt,Gp9Okg8trkMfA tAYuSTbzy!5zznCH K,bc 9bHqBWJ y3HyobsD2G7.jVznh21UUUuTw2
    1.42 +!PI7p GDvl, d6wOhHqHrjZZ5VxOHrN96a8n DsPrfFGd4z CEIupKxlhi1sMFqJio.EvgWzBfkga9
    1.43 +fEtMx4AXdkMI?U2Y4h.0PVXty4T6UT ?aICKEEjlt xhJphCJWEesfMDzhYw2ekRr gwxCXe5IYD,kJY6Sgp, uNTw0KPlf6OYuBF
    1.44 +jZRmGFJSIEmrvbbfrxRq8iSdfid okWKno.vw8B5Dqm1FCX,1qg!O,S X,YYX NACZx1Z?.GhyZrfy XDYLW,iFMVIMvkex
    1.45 +gjejzPt9suoM H PH?n0WvLs6ccf7OHe,p O8xMqg16sZg8J kIsVyaS!4,,I9R0pV
    1.46 +o cToV UWxTjH3v2PG jYKW XWEWZbopjFYMcPk1B3zK,KBCTWnV
    1.47 +ZI7XRVav DVDDlkVJaaD1o3 t7yDmwqn7oZMYcY9hV o6qYGGbM0CG .Dd4tNkUJ
    1.48 +XbN?bNV,WYuAZ2JeFKkNPyVxTB 4zLI.rbmGs06B0rG jUi gI6, Rk2Um.
    1.49 +17jgXKpFJkILPTP1 1gHYe8kwjbFJO3ZNdjorLv2?5EF z92OgAO0Z?vlS2.iv,xOya5mK cE5 WTjOjDT!EVp189vvjgkUw8xrl9e
    1.50 +EaoeuKwTSDJzc?Rz!ZJyhvv sh0ShfWp5ZJrO6YiAJ9eAO52PDO!1Z lkJ3GqP.nS8 i5WD8iE mVadphvgywr
    1.51 +X23f H LbPjYK5EJcMoBjDiNnTvYDb9cT393 PDfjofvln7A!nGbss TZcTG3TmMKkFO!
    1.52 +vz4NJ 2IiuxrIdX!?aRIiKg auth9 xv0rZKH3VumHa,p?odN7px I5k4oE4M5pNkrawk,eL
    1.53 +6YlwoD0 v,x4tV?Xcu WX?8 RtoFM!BI3q7iw6Ihw6dePR3vY GzWEfo!GvEY!R3gMaSJm27jUc!mUm
    1.54 +!vDL2l2uvp1ve pZXFVjvLhThYJJWx1Li bziUJS9ZCeKwf 41HoBr7nrF?A4rPdnu5LBD CGniTXB5P6B7Yu3naAbe8Gxa.
    1.55 +U0nbg mGO5iU?!O5 Prs5Fw mtgzIS9hRl0?Sl0igj5WaISN 86XDtwtcPHmmFI5sIv0vwkRVe
    1.56 +wr90G77hBpRwEk4 JZ4EvB2x!pVF01?vi,vsxtM? hkfHf TgJbPOUADYzN0RBx13ijp ,d
    1.57 +XCGgky FjSX?pb6r2IqHOcYGZl.RyR6wyDP0 GE cg3E71.1Ye0R6Za mNPAiK?6RG5.O
    1.58 +1ujx1fn XpGX7DaWCCnUEIj7E2 ApVDhCoS8J5mimw7i!X67diPl ?h?tm2 774BnMY.JoUxyRTOqNKHxduf
    1.59 +OUA3Ma IV5xk7lvk6i0L1N FbB56xzPBuS77wxHEt7spidOfANs3d Z4q61cXGfGcbDLN V9MCnwi4OkG9fmmihRgyw3gSY8w
    1.60 +LAykYnorzLjr? rVWT33nySaS!tT!fcCh1okf P4e lUiPr4mi?M9HrS0Xo15E5d9iAd!SW I8ruOUr35gG5p,LrJ1iF9cl7Zpz4
    1.61 +.NHx52BPj6JCCFw2UcCLYKJe,Hic bzWrkHke ")
    1.62 +
    1.63 +(defn decryptor [n]
    1.64 +  (let [ALAPHABET (reverse (map char (range 65 91)))
    1.65 +	alaphabet (reverse (map char (range 97 123)))
    1.66 +	n (if (> 0 n) (+ 26 (rem n 26)) n)]
    1.67 +    (fn [c]
    1.68 +      (first
    1.69 +       (drop n
    1.70 +	     (drop-while
    1.71 +	      (comp not #{c})
    1.72 +	      
    1.73 +	      
    1.74 +	      (cond (Character/isUpperCase c) (cycle ALAPHABET)
    1.75 +		    (Character/isLowerCase c) (cycle alaphabet)
    1.76 +		    true                      (repeat c))))))))
    1.77 +
    1.78 +(defn decrypt [n s]
    1.79 +  (apply str (map (decryptor n) (seq s))))
    1.80 +
    1.81 +(defn str->int [s]
    1.82 +  (Integer/parseInt (trim s)))
    1.83 +
    1.84 +(def a ["/home/r/coderloop-test/spiesstory-a.in"])
    1.85 +
    1.86 +
    1.87 +(defn doit [a]
    1.88 +  (let [lines (read-lines (first a))
    1.89 +	num (str->int (first lines))
    1.90 +	text (rest lines)]
    1.91 +    (dorun (map
    1.92 +	   (fn [line]
    1.93 +	     (println (decrypt num line)))
    1.94 +	   text))))
    1.95 +
    1.96 +(if (command-line?)
    1.97 +  (doit *command-line-args*))
    1.98 +