Skip to content

Instantly share code, notes, and snippets.

@zokier
Forked from b1nary/AES_over_IRC.rb
Created June 15, 2012 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zokier/2936690 to your computer and use it in GitHub Desktop.
Save zokier/2936690 to your computer and use it in GitHub Desktop.
AES and some more encryptions over IRC

AES over IRC

In this experiment i use Ruby and OpenSSL to create secure crypted conversations over irc.

  • Uses key files
  • Multiple users can chat together
  • supports any decryption ssl supports

Those are viewable in the watch out for the "modules" variable. Note that note that not every OS/ssl version/installation has the same modul set

Yes, you need to modify the source to use it

#!/usr/bin/ruby
require 'socket'
require "base64"
require "open3"
server = "localhost"
port = "6667"
nick = "Nickname#{rand(5000)}"
channel = "#channel"
key = "hunter2"
def encrypt(text,key)
ciphertext = ""
Open3.popen2("gpg --symmetric --passphrase-fd 0 --batch --no-tty --logger-file /dev/null") {|stdin, stdout, wait|
stdin.puts(key)
stdin.puts(text)
stdin.close()
ciphertext = stdout.read()
}
return ciphertext
end
def decrypt(text,key)
cleartext = ""
Open3.popen2("gpg --decrypt --passphrase-fd 0 --batch --no-tty --logger-file /dev/null") {|stdin, stdout, wait|
stdin.puts(key)
stdin.write(text)
stdin.close()
cleartext = stdout.read()
}
return cleartext
end
$s = TCPSocket.open(server, port)
print("addr: ", $s.addr.join(":"), "\n")
print("peer: ", $s.peeraddr.join(":"), "\n")
$s.puts "USER testing 0 * Testing"
$s.puts "NICK #{nick}"
$s.puts "JOIN #{channel}"
$s.puts "PRIVMSG #{channel} :Hello from IRB Bot"
Thread.new {
until $s.eof? do
msg = $s.gets
msx = msg.split(" ")
mse = msg.split("#{channel} :")[1]
if msx[1] == "PRIVMSG"
if mse.start_with?("[~]")
mse = mse.gsub('[~]','').chomp()
mse = Base64.urlsafe_decode64(mse);
mse = decrypt(mse,key)
end
puts "> #{mse}"
end
if msx[1] == "396"
$s.puts "JOIN #{channel}"
end
end
}
while true
inp = gets.chomp()
inp = encrypt(inp,key)
inp = Base64.urlsafe_encode64(inp);
puts "| #{inp}"
$s.puts "PRIVMSG #{channel} :[~]#{inp}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment