1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

Adding a Rex library method for generating an array of mixed case strings.

git-svn-id: file:///home/svn/framework3/trunk@8841 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Tod Beardsley 2010-03-17 17:47:08 +00:00
parent 984890a2cd
commit a29ff6f435

View File

@ -416,7 +416,7 @@ module Text
end
#
# Encode a string in a manor useful for HTTP URIs and URI Parameters.
# Encode a string in a manner useful for HTTP URIs and URI Parameters.
#
def self.html_encode(str, mode = 'hex')
case mode
@ -449,6 +449,29 @@ module Text
return buf
end
#
# Takes a string, and returns an array of all mixed case versions.
#
# Example:
#
# >> Rex::Text.to_mixed_case_array "abc1"
# => ["abc1", "abC1", "aBc1", "aBC1", "Abc1", "AbC1", "ABc1", "ABC1"]
#
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}
this_str = ""
c.each_with_index { |d,i| this_str << letters[i][d] }
mixed << this_str
end
return mixed.uniq
end
#
# Converts a string a nicely formatted hex dump
#