Parallel brute force: Difference between revisions

Content deleted Content added
Line 759:
import Control.Monad (replicateM, join)
import Control.Monad.Par (runPar, get, spawnP)
import Data.Text ByteString (Textpack, packByteString)
import Data.Text.Encoding (encodeUtf8)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
import DataGHC.Text.EncodingWord (encodeUtf8Word8)
 
hashedValues :: [Digest SHA256]
Line 771:
]
 
wordVariations :: [Text[Word8]]
wordVariations = pack <$> replicateM 5 ['a'97..'z'122]
 
bruteForce :: Int -> [Text[Word8]] -> [(String, TextString)]
bruteForce n xs = runPar $ join <$> (mapM get =<< mapM (spawnP . foldr findMatch []) chunks)
where
chunks = chunksOf (26^5 `div` n) xs
findMatch s accum
| hashed `elem` hashedValues = (show hashed, sshow str) : accum
| otherwise = accum
where
hashedstr = hashWith SHA256 (encodeUtf8pack s)
hashed = hashWith SHA256 str
 
main :: IO ()