-7

As the title says, how would one go about cracking a sha256 hash via brute-force with ruby?

I have searched everywhere, but I can't find anything. I am trying to decrypt it from a string input from the user.

Pixelz
  • 171
  • 1
  • 2
  • 8
  • 1
    simple answer = you can't – bansi May 23 '16 at 05:08
  • 3
    SHA-256 is a one-way hashing function. There is no "decrypting". The concept does not apply. – Calle Dybedahl May 23 '16 at 05:09
  • 1
    Do some homework here http://crypto.stackexchange.com/questions/12392/calculation-of-time-to-crack-sha-256-hash – gmuraleekrishna May 23 '16 at 05:12
  • please read the question. how do i crack it via bruteforce, meaning it would keep hashing random strings in order and comparing them. – Pixelz May 23 '16 at 05:12
  • 1
    how much time you think you can put in? http://stackoverflow.com/questions/6776050/how-long-to-brute-force-a-salted-sha-512-hash-salt-provided – bansi May 23 '16 at 05:13
  • that is java. i am asking for ruby code to do this. – Pixelz May 23 '16 at 05:15
  • bansi as much as i want – Pixelz May 23 '16 at 05:15
  • I think @bansi is thinking light-years. – Cary Swoveland May 23 '16 at 05:18
  • these are simple hashes i am testing against. im thinking more like minutes – Pixelz May 23 '16 at 05:18
  • 1
    I just did a calculation. assuming the string length as 10 chars having alpha numeric and special chars, you may require only 664 thousand years. try this calculator http://calc.opensecurityresearch.com/ – bansi May 23 '16 at 05:19
  • 5 letter strings are the test subject, tho thanks for the calc. – Pixelz May 23 '16 at 05:19
  • 5 letters may take about 47 mins – bansi May 23 '16 at 05:21
  • so, any wau to code this? – Pixelz May 23 '16 at 05:21
  • 3
    no special code, generate all 5 char strings, then generate the sha256 of that string, compare with what you have. – bansi May 23 '16 at 05:23
  • but how would i get ruby to automate it for me? – Pixelz May 23 '16 at 05:25
  • The question is who will finish first, your computer working on that problem or the proverbial room full of monkeys hitting keys randomly until they produce the text of Hamlet. – Cary Swoveland May 23 '16 at 05:26
  • nice analogy. i think my server room will do. – Pixelz May 23 '16 at 05:27
  • @CarySwoveland I think the monkeys will finish first with anything more than 8 chars – bansi May 23 '16 at 05:28
  • 1
    Welcome to Stack Overflow! Asking us to write your code for you, especially something trivial, is [off-topic](http://stackoverflow.com/help/on-topic) here. If you give it a shot yourself and post what you've tried, we can help you out. – Schwern May 23 '16 at 05:47
  • @Schwern A fair number of people do agree with you that "asking us to write your code" is off-topic, does the page you linked to make that official? I don't see where it says that. – Wayne Conrad May 23 '16 at 06:02
  • @WayneConrad I looked around and found [a meta post about why it's not there](http://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x). The consensus appears to be it's a corollary of "does not show any research effort" downvote reason, and the "shortest code necessary to produce the problem" from "seeking debugging help". Why isn't it spelled out clearer? Dunno, ask a moderator? – Schwern May 23 '16 at 06:13
  • @Schwern Thanks--that's what I was looking for. My understanding of [the top-voted answer](http://meta.stackoverflow.com/a/253096/238886) is that a downvote is appropriate for asking to write code, but unless it's too broad or has some other problem, a close vote is not. – Wayne Conrad May 23 '16 at 06:18
  • @CarySwoveland, light years are not a measure of time. (: – ndnenkov May 23 '16 at 06:46

1 Answers1

3

I'm not going to write your code for you, but I will give you a start.

  1. Create an array of all letters and digits.
  2. Use Array#repeated_permutation to go through all possible 5 character strings.
  3. Use the Digest module to generate the SHA-256 digest.
Community
  • 1
  • 1
Schwern
  • 153,029
  • 25
  • 195
  • 336