Parallel brute force: Difference between revisions
Content deleted Content added
Line 755:
Compile with "-O2 -threaded -rtsopts". Run with "+RTS -N<number of cores>"
<lang haskell>import
import
import Control.Monad (replicateM, join)
import Control.Monad.Par (runPar, get, spawnP)
import Data.ByteString (pack
import Data.List.Split (chunksOf)
import Text.Printf (printf)
hashedValues :: [Digest SHA256]
Line 771 ⟶ 770:
]
▲bruteForce :: Int -> [[Word8]] -> [(String, String)]
▲bruteForce n xs = runPar $ join <$> (mapM get =<< mapM (spawnP . foldr findMatch []) chunks)
where
chunks = chunksOf (26^5 `div` n)
findMatch s accum
| hashed `elem` hashedValues = (show hashed, show
| otherwise = accum
where
hashed = hashWith SHA256
main :: IO ()
Line 789 ⟶ 785:
cores <- getNumCapabilities
printf "Using %d cores\n" cores
mapM_ (uncurry (printf "%s -> %s\n")) (bruteForce cores
{{out}}
<pre>brute +RTS -N2 -s
|