Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2012 15:51
Show Gist options
  • Save anonymous/1583528 to your computer and use it in GitHub Desktop.
Save anonymous/1583528 to your computer and use it in GitHub Desktop.
method_missing
require 'socket'
module CryptPuts
attr_accessor :aeskey
def puts str
super("encrypted: #{str}")
end
def gets
decrypt(super)
end
def decrypt(str)
str.gsub("encrypted: ","")
str + " decrypted"
end
end
class CryptSocket
attr_accessor :socket
def self.construct(socket)
crypt=CryptSocket.new
crypt.socket=socket
return crypt
end
def initialize(*param,&block)
if param!=[]
@socket=TCPSocket.new(*param,&block)
end
end
def method_missing(name,*params,&block)
@socket.__send__(name,*params,&block)
end
#include CryptPuts
end
class CryptServer < TCPServer
def accept
CryptSocket.construct(super)
end
end
serv = CryptServer.new("1337")
serv=serv.accept
=begin
sock = CryptSocket.new("localhost",1337)
sock.puts "Ohai"
puts sock.gets
sock.close
=end
while true do
puts serv.gets
serv.puts "thx"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment