Parallel brute force: Difference between revisions
Content added Content deleted
(Added Sidef) |
(added Haskell) |
||
Line 743: | Line 743: | ||
mmmmm 74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f |
mmmmm 74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
|||
<lang haskell>{-# LANGUAGE OverloadedStrings #-} |
|||
import Data.Text (Text, pack) |
|||
import Data.Text.Encoding (encodeUtf8) |
|||
import Crypto.Hash (hashWith, SHA256 (..), Digest, digestFromByteString) |
|||
import Control.Monad (replicateM, join) |
|||
import Data.List.Split (chunksOf) |
|||
import Control.Monad.Par (runPar, get, spawnP) |
|||
import Text.Printf (printf) |
|||
hashedValues :: [Digest SHA256] |
|||
hashedValues = fmap read |
|||
[ "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b" |
|||
, "74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f" |
|||
, "1115dd800feaacefdf481f1f9070374a2a81e27880f187396db67958b207cbad" |
|||
] |
|||
wordVariations :: [Text] |
|||
wordVariations = pack <$> replicateM 5 ['a'..'z'] |
|||
bruteForce :: [Text] -> [(String, Text)] |
|||
bruteForce xs = runPar $ do |
|||
pars <- mapM (spawnP . foldr findMatch []) chunks |
|||
result <- mapM get pars |
|||
pure $ join result |
|||
where |
|||
chunks = chunksOf (26 ^ 4 * 26 `div` 10) xs |
|||
findMatch s accum |
|||
| hashed `elem` hashedValues = (show hashed, s) : accum |
|||
| otherwise = accum |
|||
where |
|||
hashed = hashWith SHA256 (encodeUtf8 s) |
|||
main :: IO () |
|||
main = mapM_ (uncurry (printf "%s -> %s\n")) (bruteForce wordVariations)</lang> |
|||
{{out}} |
|||
<pre>3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b -> apple |
|||
74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f -> mmmmm |
|||
1115dd800feaacefdf481f1f9070374a2a81e27880f187396db67958b207cbad -> zyzzx |
|||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{works with |Java| 1.5}} |
{{works with |Java| 1.5}} |