Add the ror/rol ror13hash code to msf3

git-svn-id: file:///home/svn/framework3/trunk@5627 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2008-08-13 01:44:37 +00:00
parent 33afd40526
commit 9903e0bb1d
1 changed files with 33 additions and 0 deletions

View File

@ -932,6 +932,39 @@ module Text
States[rand(States.size)]
end
#
# Calculate the ROR13 hash of a given string
#
def self.ror13_hash(name)
hash = 0
name.unpack("C*").each {|c| hash = ror(hash, 13); hash += c }
hash
end
#
# Rotate a 32-bit value to the right by cnt bits
#
def self.ror(val, cnt)
bits = [val].pack("N").unpack("B32")[0].split(//)
1.upto(cnt) do |c|
bits.unshift( bits.pop )
end
[bits.join].pack("B32").unpack("N")[0]
end
#
# Rotate a 32-bit value to the left by cnt bits
#
def self.rol(val, cnt)
bits = [val].pack("N").unpack("B32")[0].split(//)
1.upto(cnt) do |c|
bits.push( bits.shift )
end
[bits.join].pack("B32").unpack("N")[0]
end
protected
def self.converge_sets(sets, idx, offsets, length) # :nodoc: