2005-06-09 04:36:02 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Encoder
|
|
|
|
|
|
|
|
class Xor
|
|
|
|
|
2005-06-09 18:12:39 +00:00
|
|
|
attr_accessor :raw, :encoded, :badchars, :opts, :key, :fkey
|
2005-06-09 04:36:02 +00:00
|
|
|
|
|
|
|
# wrap that shit in a wanna be static class
|
|
|
|
def self.encode(*args)
|
|
|
|
self.new.encode(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def encoder()
|
|
|
|
self.class::EncoderKlass
|
|
|
|
end
|
|
|
|
|
2005-06-09 04:47:12 +00:00
|
|
|
def encode(data, badchars = '', opts = { })
|
2005-06-09 04:36:02 +00:00
|
|
|
self.raw = data
|
|
|
|
self.badchars = badchars
|
|
|
|
self.opts = opts
|
|
|
|
|
2005-06-09 18:22:39 +00:00
|
|
|
# apply any transforms to the plaintext data
|
|
|
|
data = _unencoded_transform(data)
|
|
|
|
|
2005-06-09 18:12:39 +00:00
|
|
|
self.encoded, self.key, self.fkey = encoder().find_key_and_encode(data, badchars)
|
2005-06-09 18:22:39 +00:00
|
|
|
|
|
|
|
# apply any transforms to the encoded data
|
|
|
|
self.encoded = _encoded_transform(encoded)
|
|
|
|
|
2005-06-09 04:36:02 +00:00
|
|
|
return _prepend() + encoded + _append()
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2005-06-09 18:23:30 +00:00
|
|
|
def _unencoded_transform(data)
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
|
|
|
def _encoded_transform(data)
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2005-06-09 04:36:02 +00:00
|
|
|
def _prepend()
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
def _append()
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end end
|