2021年3月10日星期三

ruby - How to make an array of arrays of letters (a-z) of varying lengths with maximum length five

So I'm trying to make an array of all possible permutations of the alphabet letters (all lowercase), in which the letters can repeat and vary in length from 1 to 5. So for example these are some possibilities that would be in the array:

['this','is','some','examp','le']  

I tried this, and it gets all the variations of words 5 letters long, but I don't know how to find varying length.

("a".."z").to_a.repeated_permutation(5).map(&:join)  

EDIT:

I'm trying to do this in order to crack a SHA1 encrypted string:

require 'digest'  def decrypt_string(hash)    ("a".."z").to_a.repeated_permutation(5).map(&:join).find {|elem| Digest::SHA1.hexdigest(elem) == hash}  end  

Hash being the SHA1 encryption of the word, such as 'e6fb06210fafc02fd7479ddbed2d042cc3a5155e'

https://stackoverflow.com/questions/66572907/ruby-how-to-make-an-array-of-arrays-of-letters-a-z-of-varying-lengths-with-m March 11, 2021 at 05:11AM

没有评论:

发表评论