Parallel brute force: Difference between revisions

m
Line 795:
<lang haskell>import Control.Concurrent (forkIO, setNumCapabilities)
import Control.Concurrent.Chan (Chan, newChan, readChan, writeList2Chan)
import Control.Monad (replicateM, foreverreplicateM_, replicateM_forever)
import Crypto.Hash (SHA256(..), Digest, hashWith)
import Data.Bifunctor (first)
import Data.ByteString (ByteString, pack)
import Data.Char (isDigit)
import Data.List.Split (chunksOf)
Line 818:
chunks = chunksOf (10^3) $ replicateM 5 [97..122]
 
findMatch :: [TestString -> [(Encrypted, Decrypted)] -> [(Encrypted, Decrypted)]
findMatch []w = []acc
| hashed `elem` hashedValues = (hashed, show bStr):findMatch xsacc
findMatch (x:xs)
| otherwise = findMatch xsacc
| hashed `elem` hashedValues = (hashed, show bStr):findMatch xs
| otherwise = findMatch xs
where
bStr = pack xw
hashed = hashWith SHA256 bStr
 
searchWorker :: Chan [TestString] -> Chan (Encrypted, String) -> IO ()
searchWorker batchChan resultChan = forever (readChan batchChan >>= writeList2Chan resultChan . foldr findMatch [])
 
parseInput :: [String] -> Int
parseInput [] = 2
Anonymous user