lib/rex/text/randomize.rb in rex-text-0.2.20 vs lib/rex/text/randomize.rb in rex-text-0.2.21
- old
+ new
@@ -33,22 +33,18 @@
#
# @param str [String] The string to randomize
# @return [Array<String>]
# @see permute_case
def self.to_mixed_case_array(str)
- letters = []
- str.scan(/./).each { |l| letters << [l.downcase, l.upcase] }
- coords = []
- (1 << str.size).times { |i| coords << ("%0#{str.size}b" % i) }
- mixed = []
- coords.each do |coord|
- c = coord.scan(/./).map {|x| x.to_i}
+ letters = str.each_char.map { |l| [l.downcase, l.upcase] }
+ (1 << str.size).times.map do |i|
this_str = ""
- c.each_with_index { |d,i| this_str << letters[i][d] }
- mixed << this_str
- end
- return mixed.uniq
+ ("%0#{str.size}b" % i).each_char.map(&:to_i).each_with_index do |d,i|
+ this_str << letters[i][d]
+ end
+ this_str
+ end.uniq
end
#
# Randomize the whitespace in a string
#
@@ -81,21 +77,10 @@
# Modifies +arr+ in place
#
# @param arr [Array] The array to be shuffled
# @return [Array]
def self.shuffle_a(arr)
- len = arr.length
- max = len - 1
- cyc = [* (0..max) ]
- for d in cyc
- e = rand(d+1)
- next if e == d
- f = arr[d];
- g = arr[e];
- arr[d] = g;
- arr[e] = f;
- end
- return arr
+ arr.shuffle!
end
# Permute the case of a word
def self.permute_case(word, idx=0)
res = []