Created
December 7, 2019 00:01
-
-
Save dfuenzalida/52f63122f19ccf0ed82ef10a1362deeb to your computer and use it in GitHub Desktop.
SHA-512 bruteforce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns demo.bruteforce) | |
(defn sha-512 [s] | |
(let [digester (java.security.MessageDigest/getInstance "SHA-512")] | |
(->> (.digest digester (.getBytes s)) | |
(map (partial format "%02x")) | |
(apply str)))) | |
(def charset | |
(into [""] (map str "abcdefghijklmnopqrstuvwxyz"))) | |
(defn crack [target] | |
(first | |
(for [c1 charset | |
c2 charset | |
c3 charset | |
c4 charset | |
:let [candidate (str c1 c2 c3 c4)] | |
:when (= target (sha-512 candidate))] | |
candidate))) | |
;; (sha-512 "help") | |
;; => "5766d45bdba1152105abfd9662e551401a9756f1a37b3a3669ac590390479e9220591027098d61eff70ed6d0314d2cac7128f488df052ed7318ead76ba5f2f7b" | |
;; (time (crack "5766d45bdba1152105abfd9662e551401a9756f1a37b3a3669ac590390479e9220591027098d61eff70ed6d0314d2cac7128f488df052ed7318ead76ba5f2f7b")) | |
;; "Elapsed time: 7417.7162 msecs" | |
;; => "help" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`// In Rust
#[macro_use]
extern crate itertools;
use sha2::{Digest, Sha512};
fn main() {
let target = Sha512::new().chain(b"help").result();
let alpha = "abcdefghijklmnopqrstuvwxyz";
let col = iproduct!(alpha.chars(), alpha.chars(), alpha.chars(), alpha.chars())
.map(|(a, b, c, d)| format!("{}{}{}{}", a, b, c, d))
.filter(|candidate| Sha512::new().chain(&candidate).result() == target)
.collect::<Vec>();
println!("{:?}", col);
}
`