EG Information
Training Missions
Knowledge Bank
Pimp Us Out!
Has Enigma Group Helped You? Then Help Us By Advertising For Us. Place One Of The Following Images On Your Site And Create A Link Back To Enigma Group.
|
| |
Affiliates
|
|
Enigma Group's Code Bank
The Caesar CipherBy: ParadoxMAI - Date Submitted: 2011-12-18 20:23:56 import Data.List import Test.QuickCheck import Data.Function rotate k list | 0 <= k && k <= length list = drop k list ++ take k list prop_rotate k str = rotate (l - m) (rotate m str) == str m = if l == 0 then 0 else k ` mod` l -- prop_rotate rotates a list of lenght l first an arbitrary number m times, -- and then rotates it l-m times; together (m + l - m = l) it rotates it all -- the way round, back to the original list -- -- to avoid errors with 'rotate', m should be between 0 and l; to get m -- from a random number k we use k `mod` l (but then l can't be 0, -- since you can't divide by 0) alphabet = ['A'..'Z'] makeKey k = zip alphabet (rotate k alphabet ) . lookUp ch [] = ch lookUp ch ((key,val):restKey) | key == ch = val -- alternative solution with list-comprehension -- -- lookUp ch xs = head ([ y | (x,y) <- xs, x == ch] ++ [ch]) encipher k ch = lookUp ch (makeKey k) normalize [] = [] normalize (ch:str) | isAlpha ch = toUpper ch : normalize str | isDigit ch = ch : normalize str encipherStr k str = [encipher k ch | ch <- normalize str] reverseKey key = [(b, a) | (a, b) <- key] decipher k ch = lookUp ch (reverseKey (makeKey k)) decipherStr k str = [decipher k ch | ch <- str] prop_cipher k str = decipherStr l (encipherStr l str) == normalize str contains _ [] = True contains [] _ = False contains str substr = isPrefixOf substr str || contains (tail str ) substr . candidates str = [(i, decipherStr i str) | i <- [0..25], candidate (decipherStr i str)] where candidate str = str `contains` "AND" || str `contains` "THE" splitEachFive xs | length xs > 5 = take 5 xs : splitEachFive (drop 5 xs ) fillToFive xs = xs ++ replicate (5 - length xs ) 'X' -- An alternative solution demonstrating 'repeat' prop_transpose xs = ys == transpose (transpose ys) where ys = splitEachFive xs encrypt n str = concat (transpose (splitEachFive (encipherStr n str ))) splitFiveWays xs | n ` mod` 5 == 0 = splitEach (n ` div` 5) xs splitEach _ [] = [] splitEach n xs = take n xs : splitEach n (drop n xs ) decrypt n str = concat (transpose (splitFiveWays (decipherStr n str ))) -- Increment a frequency in a character frequency list. incAsc c [] = [(c,1)] incAsc c ((d,n) : xs) | c == d = (d, n+1) : xs countFreqs xs = count xs [] where count [] freqs = freqs count (x : xs) freqs = count xs (incAsc x freqs) -- Rank the candidates which might decipher to 'E' freqCandidates xs = [ (ord c - ord 'E' ) ` mod` 26 | (c , _) <- freqChars ] where freqChars = sortBy p (countFreqs xs) freqDecipher xs = [ decrypt n xs | n <- freqCandidates xs ]
|
| Return to
haskell category list |
|
|
Who Visited EnigmaGroup Today?
1387 Guests, 225 Users (218 Spiders)
lolzsec, tgm001, plex, Edika, TheCheeseDemon, rockcraft, Pabz, recoveryToolbox, saraf, soufiaane, sickmind, cat1vo, mjneat, famous0123, Galagatron, dark_void, CJ_Omaha, junaid_junaid59, JohnJohnJohn, ssmaslov, psychomarine, Dregoon, Patrickk, Aska, Beat_Slayer, M0rdak, Ausome1, Imre, Vreality2007, mmndglxuwn, m0rt, unholyblood, iterrumzz, VurbTrurb, Mayonoula, MAMWOURBROR, mutabor, gobinda, cossyDrybrich, Razin, zaCruBumas8, hunja, johny34, pantoufle, bagy, arctica, hackarchives, UsedDeteKef, Peculator, Fadhilat606, TheTrueMonarch, Pascall01, hackaday, Tjm, arndevil, flairvelocity, lol, alphbond, kdivanov, elizbethallis6, Rik, bn11, BorgBot, SHASHANK101hello, 4poc4lyptic, ksajxai, nbmorri1, electro-technic, شمالي عرعر, lamb, AutobotPrime, Underleaf, The End, tomtombomb, killobyte, snowgirlx, so_saucey, zerolife, Althor, Cramps, Hekser, Hyperborn, cyber-guard, jhgrunn, cobra, Partisan, MAZI_, cyborg, GenbreedX, moel77, cliptoX, pwnpwnlolz, letshavepie, Mrwormz, yshiau, mirmo, roozyoppomo, soft_devil, cls777, scoobywan, Reiversed, joshua, st3alth, Afrika, PaiffDryday, venter, Anthony12796, sh3llcod3, 8FIGURE, Rannim, Evil1, maloaboy, BACanON, SlayingDragons, Repuhlsive, IvanDimitriev, 1RiB, mzungudo, Micro_Geek, iMaxx, aciboummamymn, k0unterkulcher, somebody777, m14m16, GoododotAlcob, negasora, Rastii, UninueMem, Swifsolja, ad.conquest, ngolatkar, Infinity8, Jigoku, thesupervisor, p0is0n5ting, kernel_mod, AKL, GothicLogic, themastersinner, dnatrixene135, ChewBigRed, kalak55, sejem, cve916, pollolololo, triecturn, Violatedsmurf, Ops, jmp, xsiemich, generalisimo, strudels, ga3ttpom, KingOfBritains, epoch_qwert, suten, FriskyKat, Ryuske, Adonis Achilles, ubqbcdzzhf, 3vil, Nightraven, US£RNAM£, Weindittewcon, Batesheelocot, GSmyrlis, MaxMeier, Elite.America, rabbidmind, Psiber_Syn, phoenix22, imittyerrotte, peewster, cyberturtle, ctb, dexgeda, sdw, Pizza, White_widdow, devarian, finesse, Nature112091777, Danc7171, Alphadragon, Estadagause, 53QR10U5, Xargos, Alkomage, hardlock, Barry Gonzoles, MineDweller, Gkjt, N4g4c3N, [I]nfectedbug, wimsteege, aqr5zdcw, xin214, Bugshuppy, SnoopSky, Hessesian, voodooKobra, sKcarr, IROverRated, W1F1G3NJU75U, Baddy, ziadmosaan, gamble86, realzs, CruelDemon, Shinju, aVoid, aquiredanonymity, kukumumu, web_request, callmeneon, KissMyDAFFODIL, Feld Grau, Abhinav2107, prabhataditya, mbuyiselo, shumer, phenom216, princennamdi, huskyboiza, ninety-nine |
| |
|
|
|
|
|