# EncryptDecrypt v1.0
#
# This is just a little script that demonstates 1 way of
# working with Mircryption via an Eggdrop bot. It both
# recieves encrypted commands, and transmits encrypted
# responses. It's crude, but it works.
# It also addresses the space compaction that Mirc does
# on a line when there is more than one space between characters.
# Thanks Dark Raiche for the tip on this.
# Credits:
# Dark Raichu, http://mircryption.sourceforge.net - For Mircryption & the chr(160) idea
# Gizzmo - For helping me figure all this out
# Set the Mircryption key for you channel here
# Note: This is not very safe, so be cautious as to who has access to your bot
set chankey "!negative"
# This is what catches the encrypted cmds
bind pub -* mcps pub:getcmd
# Example of recieving either an encrypted or decrypted command
bind pub - "!either" pub:either
# This routine catches all encrypted messages, decides if they are a command,
# and calls the appropiate routine if they are
proc pub:getcmd {nick host hand chan text } {
# Set the channel key
global chankey
# Decrypt the message
set plaintext [decrypt $chankey $text]
# Parse out the begining for the commands with an argument
set SpecialCmd [string range $plaintext 0 7]
# Get the argument
set arg [string range $plaintext 8 end]
# Check for the special commands
if {$SpecialCmd == "!special"} { pub:special $nick $host $hand $chan $arg }
if {$SpecialCmd == "!tspaces"} { pub:tspaces $nick $host $hand $chan $arg }
proc pub:special { nick host hand chan arg } {
global chankey
# Send back the argument, encrypted
putserv "privmsg $chan :mcps [encrypt $chankey "$nick: Your command argument was $arg"]"
}
proc pub:enccmd { nick host hand chan text } {
global chankey
# Send back the command encrypted
putserv "privmsg $chan :mcps [encrypt $chankey "$nick: Your command was: $text"]"
}
proc pub:either { nick host hand chan text } {
global chankey
set botnick "StupidBot"
# See if it was an unencrypted command
if { $text == ""} {
# If so, talk unencrypted
putserv "privmsg $chan :$nick: $botnick talks decrypted. :)"
} else {
# Else talk encrypted
putserv "privmsg $chan :mcps [encrypt $chankey "$nick: $botnick talks encrypted. :)"]"
}
}
proc pub:rspaces { nick host hand chan text } {
global chankey
# Demonstrate a line with multispaces between characters
set sLine "T E S T I N G 1 2 3"
# \xA0 represents A0h (hex), which is 160 decimal or the invisible character
# Fill all spaces with the invisible character
putserv "privmsg $chan :mcps [encrypt $chankey [string map {" " "\xA0"} $sLine]]"
}
proc pub:tspaces { nick host hand chan arg } {
global chankey
# Get the length of $arg
set cnt [string length $arg]
# Prep stop point
set sChar 0
# Set a blank string to accumalate the spaced string
set sReturn ""
# Check to see if there is anything to space
if { $cnt > 0 } {
# If so, insert 3 spaces before each character
for {set i 0} {$i < $cnt} {incr i} {
set sReturn "$sReturn[string range $arg $i $sChar]\xA0\xA0\xA0"
incr sChar
}
# Send the spaced string back to the channel
putserv "privmsg $chan :mcps [encrypt $chankey $sReturn]"
}
}