Parallel brute force: Difference between revisions

m
Line 755:
Compile with "-O2 -threaded -rtsopts". Run with "+RTS -N<number of cores>"
 
<lang haskell>import CryptoControl.Hash Concurrent (hashWith, SHA256 (..), DigestgetNumCapabilities)
import ControlCrypto.ConcurrentHash (getNumCapabilitieshashWith, SHA256 (..), Digest)
import Control.Monad (replicateM, join)
import Control.Monad.Par (runPar, get, spawnP)
import Data.ByteString (pack, ByteString)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
import Data.Word (Word8)
 
hashedValues :: [Digest SHA256]
Line 771 ⟶ 770:
]
 
bruteForce :: Int -> [[Word8]] -> [(String, String)]
wordVariations :: [[Word8]]
bruteForce n xs = runPar $ join <$> (mapM get =<< mapM (spawnP . foldr findMatch []) chunks)
wordVariations = replicateM 5 [97..122]
 
bruteForce :: Int -> [[Word8]] -> [(String, String)]
bruteForce n xs = runPar $ join <$> (mapM get =<< mapM (spawnP . foldr findMatch []) chunks)
where
chunks = chunksOf (26^5 `div` n) xs$ replicateM 5 [97..122]
findMatch s accum
| hashed `elem` hashedValues = (show hashed, show strbStr) : accum
| otherwise = accum
where
strbStr = pack s
hashed = hashWith SHA256 strbStr
 
main :: IO ()
Line 789 ⟶ 785:
cores <- getNumCapabilities
printf "Using %d cores\n" cores
mapM_ (uncurry (printf "%s -> %s\n")) (bruteForce cores wordVariations)</lang>
{{out}}
<pre>brute +RTS -N2 -s
Anonymous user