Parallel brute force: Difference between revisions
Content added Content deleted
Line 795: | Line 795: | ||
<lang haskell>import Control.Concurrent (forkIO, setNumCapabilities) |
<lang haskell>import Control.Concurrent (forkIO, setNumCapabilities) |
||
import Control.Concurrent.Chan (Chan, newChan, readChan, writeList2Chan) |
import Control.Concurrent.Chan (Chan, newChan, readChan, writeList2Chan) |
||
import Control.Monad (replicateM, |
import Control.Monad (replicateM, replicateM_, forever) |
||
import Crypto.Hash (SHA256(..), Digest, hashWith) |
import Crypto.Hash (SHA256(..), Digest, hashWith) |
||
import Data.Bifunctor (first) |
import Data.Bifunctor (first) |
||
import Data.ByteString (pack) |
import Data.ByteString (ByteString, pack) |
||
import Data.Char (isDigit) |
import Data.Char (isDigit) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
Line 818: | Line 818: | ||
chunks = chunksOf (10^3) $ replicateM 5 [97..122] |
chunks = chunksOf (10^3) $ replicateM 5 [97..122] |
||
findMatch :: |
findMatch :: TestString -> [(Encrypted, Decrypted)] -> [(Encrypted, Decrypted)] |
||
findMatch |
findMatch w acc |
||
⚫ | |||
findMatch (x:xs) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
where |
where |
||
bStr = pack |
bStr = pack w |
||
hashed = hashWith SHA256 bStr |
hashed = hashWith SHA256 bStr |
||
searchWorker :: Chan [TestString] -> Chan (Encrypted, String) -> IO () |
searchWorker :: Chan [TestString] -> Chan (Encrypted, String) -> IO () |
||
searchWorker batchChan resultChan = forever (readChan batchChan >>= writeList2Chan resultChan . findMatch) |
searchWorker batchChan resultChan = forever (readChan batchChan >>= writeList2Chan resultChan . foldr findMatch []) |
||
parseInput :: [String] -> Int |
parseInput :: [String] -> Int |
||
parseInput [] = 2 |
parseInput [] = 2 |