Created
October 19, 2014 18:11
-
-
Save cite-reader/dcd7f9559cbc9cfa3833 to your computer and use it in GitHub Desktop.
Haskell: easiest parallelization ever.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 076066f4d671c59924c2425e20e4697cbce816e0 Mon Sep 17 00:00:00 2001 | |
From: Alex Hill <[email protected]> | |
Date: Sun, 19 Oct 2014 11:06:18 -0700 | |
Subject: [PATCH] Guess in parallel. | |
--- | |
matasano-challenge.cabal | 5 +++-- | |
src/Main.hs | 3 ++- | |
2 files changed, 5 insertions(+), 3 deletions(-) | |
diff --git a/matasano-challenge.cabal b/matasano-challenge.cabal | |
index 58d5c2d..b2d4fef 100644 | |
--- a/matasano-challenge.cabal | |
+++ b/matasano-challenge.cabal | |
@@ -23,7 +23,8 @@ executable matasano-challenge | |
base16-bytestring >=0.1 && <0.2, | |
base64-bytestring >=1.0 && <1.1, | |
bytestring >=0.10 && <0.11, | |
- vector >=0.10 && <0.11 | |
+ vector >=0.10 && <0.11, | |
+ parallel >=3.2 && <3.3 | |
hs-source-dirs: src | |
default-language: Haskell2010 | |
- ghc-options: -O2 -Wall -fllvm -fPIC | |
+ ghc-options: -O2 -Wall -fllvm -fPIC -threaded -rtsopts -with-rtsopts=-N | |
diff --git a/src/Main.hs b/src/Main.hs | |
index 29967d4..2a0f66f 100644 | |
--- a/src/Main.hs | |
+++ b/src/Main.hs | |
@@ -3,6 +3,7 @@ module Main where | |
import ByteCodings (fromHex) | |
import CharFreq | |
import BitOps | |
+import Control.Parallel.Strategies | |
import qualified Data.ByteString as B | |
import Data.ByteString (ByteString) | |
import Data.Word | |
@@ -17,7 +18,7 @@ decryptions :: ByteString -> [(Freq, (Word8, ByteString))] | |
decryptions s = sortBy (comparing fst) . | |
filter (not . isNaN . fst) . | |
map (\p@(_, x) -> (proximity x, p)) $ | |
- map (\k -> (k, decrypt s k)) [minBound .. maxBound] | |
+ parMap rpar (\k -> (k, decrypt s k)) [minBound .. maxBound] | |
main :: IO () | |
main = do | |
-- | |
1.9.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment