2005-05-23 00:34:16 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Encoding
|
|
|
|
module Xor
|
|
|
|
|
|
|
|
class Generic
|
|
|
|
|
|
|
|
def Generic.keysize
|
|
|
|
# special case:
|
|
|
|
# 0 means we encode based on the length of the key
|
|
|
|
# we don't enforce any perticular key length
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2005-05-24 03:58:47 +00:00
|
|
|
def Generic.find_key(*crap)
|
|
|
|
raise NotImplementedError, "We are lazy bums!", caller
|
|
|
|
end
|
|
|
|
|
2005-05-23 00:34:16 +00:00
|
|
|
def Generic.encode(buf, key)
|
|
|
|
|
|
|
|
if !key.kind_of?(String)
|
|
|
|
raise ArgumentError, "Key must be a string!", caller
|
|
|
|
end
|
|
|
|
|
2005-05-24 03:58:47 +00:00
|
|
|
len = key.length
|
|
|
|
|
|
|
|
if len == 0
|
|
|
|
raise ArgumentError, "Zero key length!", caller
|
|
|
|
end
|
2005-05-23 00:34:16 +00:00
|
|
|
|
|
|
|
if keysize != 0 && keysize != len
|
|
|
|
raise ArgumentError, "Key length #{len}, expected #{keysize}", caller
|
|
|
|
end
|
|
|
|
|
|
|
|
encoded = ""
|
|
|
|
pos = 0
|
|
|
|
|
|
|
|
while pos < buf.length
|
|
|
|
encoded += (buf[pos] ^ key[pos % len]).chr
|
2005-05-24 03:58:47 +00:00
|
|
|
pos += 1
|
2005-05-23 00:34:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return encoded
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-05-24 03:58:47 +00:00
|
|
|
# maybe a bit a smaller of method name?
|
|
|
|
def Generic.find_key_and_encode()
|
|
|
|
end
|
|
|
|
|
2005-05-23 00:34:16 +00:00
|
|
|
|
|
|
|
end end end end # Generic/Xor/Encoding/Rex
|