longshot 0.1.0.3 → 0.1.0.4
raw patch · 6 files changed
+41/−41 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Crypto.Longshot.Internal: bruteforceDeep :: Int -> String -> String -> Hasher -> Maybe String
+ Crypto.Longshot.Internal: bruteforceDeep :: String -> String -> Hasher -> Maybe String
Files
- ChangeLog.md +6/−2
- README.md +9/−7
- app/Main.hs +6/−5
- longshot.cabal +2/−2
- src/Crypto/Longshot/Internal.hs +3/−3
- test/Spec.hs +15/−22
ChangeLog.md view
@@ -3,11 +3,15 @@ ## 0.1.0.0 * First public release * Strict and deep search mode-* Support various search length, character sets and hashers+* Support various search length, character sets, and hashers ## 0.1.0.2 * Fixed Hackage metadata ## 0.1.0.3-* Up to 10% performance improvement+* Up to 10% performance improvement while using 30% less memory * Additional explanations on the arguments of the core function++## 0.1.0.4+* Deep search performance improvement+* Clean up unnecessary arguments
README.md view
@@ -12,7 +12,7 @@ * Support various __search lengths__, __character sets__ and __hashers__. * Strict mode: searches only for a given _exact length_-* Deep mode: searches _everything less than or equal_ to a given length.+* Deep mode: Incrementally searches when you do not know the exact length of search * Use `CPUs` as _much_ as possible. __Get the most out of them!__ * Use, however, `memory` as _little_ as possible. @@ -22,10 +22,10 @@ ```plain-longshot - Fast and concise Brute-force search+longshot - Fast Brute-force search using parallelism Usage:- longshot run [-n SIZE] [-c CHARS] [-a HASHER] [--deep] HEX+ longshot run [--deep | -n SIZE] [-c CHARS] [-a HASHER] HEX longshot image [-a HASHER] KEY Commands:@@ -38,6 +38,8 @@ Options: -h --help Show this+ --deep Deep search by increasing length of search+ Use when you do not know the exact length of preimage -n SIZE Specify search length [default: 8] -c CHARS Specify characters available in preimage [default: 0123456789] -a HASHER Specify hash algorithm [default: sha256]@@ -48,7 +50,6 @@ blake3_256 blake3_384 blake3_512 keccak_256 keccak_384 keccak_512 skein_256 skein_384 skein_512- --deep Search deeply including less than a given search length ``` ## How to build@@ -90,8 +91,9 @@ $ ./longshot run 5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5 Not found -## If you don't know the key length, use deep search. (--deep)-## It will try to search with less than or equal to the given length.+## If you don't know the exact key length, use deep search. (--deep)+## In most cases, it is difficult to know the length of the preimage.+## It will try to search by increasing length of search $ ./longshot run --deep 5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5 Found 12345 ```@@ -106,7 +108,7 @@ bb40f637bb211532318965627f15bb165f701230fd83e0adf8cd673a6ee02830 ## Need different character set. Don't forget --deep-$ ./longshot run -c 'abcdefghijklmnopqrstuvwxyz' -a blake2b --deep bb40f6..e02830+$ ./longshot run --deep -c 'abcdefghijklmnopqrstuvwxyz' -a blake2b bb40f6..e02830 Found sofia ## You should consider the following if there might be more characters in preimage.
app/Main.hs view
@@ -11,10 +11,10 @@ patterns :: Docopt patterns = [docopt|-longshot - Fast and concise Brute-force search+longshot - Fast Brute-force search using parallelism Usage:- longshot run [-n SIZE] [-c CHARS] [-a HASHER] [--deep] HEX+ longshot run [--deep | -n SIZE] [-c CHARS] [-a HASHER] HEX longshot image [-a HASHER] KEY Commands:@@ -27,6 +27,8 @@ Options: -h --help Show this+ --deep Deep search by increasing length of search+ Use when you do not know the exact length of preimage -n SIZE Specify search length [default: 8] -c CHARS Specify characters in preimage [default: 0123456789] -a HASHER Specify hash algorithm [default: sha256]@@ -37,7 +39,6 @@ blake3_256 blake3_384 blake3_512 keccak_256 keccak_384 keccak_512 skein_256 skein_384 skein_512- --deep Search deeply including less than a given search length |] -- | Defines args-ops frequently used@@ -66,8 +67,8 @@ size <- (read <$> (args <->|! shortOption 'n')) :: IO Int hasher <- getHasher <$> (args <->|! shortOption 'a') let solver | args >< longOption "deep" = bruteforceDeep- | otherwise = bruteforce- let found = solver size chars hex hasher+ | otherwise = bruteforce size+ let found = solver chars hex hasher case found of Just key -> putStrLn $ "Found " <> key _ -> putStrLn "Not found"
longshot.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 950eaac57e913aaa5d3f38ed066cb8aefb07851a8072f2686280220fd76aa711+-- hash: 77e95d459d9fba67fbf3f6f7adcfb1c70e549c1c1b4bfe5c5b84ff131adef03c name: longshot-version: 0.1.0.3+version: 0.1.0.4 synopsis: Fast Brute-force search using parallelism description: Longshot enables to search for preimages from a given hash value using a brute-force method based on parallelism.
src/Crypto/Longshot/Internal.hs view
@@ -85,10 +85,10 @@ -- -- See the 'bruteforce' function for the arguments used ---bruteforceDeep :: Int -> String -> String -> Hasher -> Maybe String-bruteforceDeep size chars hex hasher = foldl' (<|>) empty found+bruteforceDeep :: String -> String -> Hasher -> Maybe String+bruteforceDeep chars hex hasher = foldl' (<|>) empty found where- found = deep chars hex hasher <%> [1 .. size]+ found = deep chars hex hasher <$> [1 .. limitSearchLength] deep a b c d = bruteforce d a b c -- | Parallel map using deepseq, par and pseq
test/Spec.hs view
@@ -45,40 +45,33 @@ , "skein_512" ] --- | Test for strict mode of Brute-force search-testLongshot :: Hasher -> Gen Bool-testLongshot hasher = do+-- | Test for { strict | deep } mode of Brute-force search+testLongshot :: String -> String -> Gen Bool+testLongshot mode algo = do size <- choose (1, limit) :: Gen Int key <- replicateM size (elements chars :: Gen Char)- let hex = C.unpack . H.encode . hasher . C.pack $ key- let found = bruteforce size chars hex hasher- case found of- Just x | x == key -> return True- _ -> return False---- | Test for deep mode of Brute-force search-testLongshotDeep :: Hasher -> Gen Bool-testLongshotDeep hasher = do- let size = limit- size' <- choose (1, limit) :: Gen Int- key <- replicateM size' (elements chars :: Gen Char)- let hex = C.unpack . H.encode . hasher . C.pack $ key- let found = bruteforceDeep size chars hex hasher+ let hasher = getHasher algo+ let hex = C.unpack . H.encode . hasher . C.pack $ key+ let solver | mode == "strict" = bruteforce size+ | otherwise = bruteforceDeep+ let found = solver chars hex hasher case found of Just x | x == key -> return True _ -> return False -- | Property test generator-genTestProp :: (Hasher -> Gen Bool) -> TestName -> TestName -> TestTree-genTestProp f desc algo = testProperty (desc <> algo) (f $ getHasher algo)+genTestProp+ :: (String -> String -> Gen Bool) -> String -> String -> String -> TestTree+genTestProp f mode desc algo = testProperty (desc <> algo) (f mode algo) -- | Main test of properties tests :: TestTree tests = testGroup "Longshot Tests"- [ testGroup "Strict-Longshot search"- (genTestProp testLongshot "testLongshot with " <$> hashers)+ [ testGroup+ "Strict-Longshot search"+ (genTestProp testLongshot "strict" "Strict longshot with " <$> hashers) , testGroup "Deep-Longshot search"- (genTestProp testLongshotDeep "testLongshotDeep with " <$> hashers)+ (genTestProp testLongshot "deep" "Deep longshot with " <$> hashers) ]