IRCrypt Addon (Standard Version) — File Browser

IRCryptAddonStandardVersionv1.0 / IRCryptAddonStandardVersionv1.0 / ircryptn.mrc

ircryptn.mrc — 25.78 KB — Download this file

; -----------------------------------------------------
; IRCrypt Addon for mIRC 5.3+ (standard version)
;  Do not use this with P&P, a P&P-specific version
;  is available.
; -----------------------------------------------------
; Basic aliases
; -----------------------------------------------------
alias -l dispa echo $colour(info) -ai2 *** $1-
alias -l disps echo $colour(info) -si2 *** $1-
alias -l _error echo $colour(ctcp) -ai2 * $1- | unset %ctemp.* | halt
; -----------------------------------------------------
; Key management
; -----------------------------------------------------
alias key {
  if ($2 == $null) { dispa Usage: /key nick/#channel key | halt }
  if ($len($2) < 3) _error Error- Key must be at least three characters long.
  if ($len($2) > 200) _error Error- Key must be shorter than 200 characters long.
  set %crypt.key. [ $+ [ $1 ] ] $2
  set %crypt.keys $addtok(%crypt.keys,$1,32)
  dispa Key for %col.target $+ $1 $+  set to %col.info1 $+ $2
}
alias viewkey {
  if ($1 == $null) {
    set %ctemp.num $gettok(%crypt.keys,0,32)
    if (%ctemp.num < 1) dispa No IRCrypt keys have been defined.
    else {
      dispa
      dispa The following IRCrypt keys have been defined-
      :loop
      dispa Key for %col.target $+ $gettok(%crypt.keys,%ctemp.num,32) $+  is %col.info1 $+ %crypt.key. [ $+ [ $gettok(%crypt.keys,%ctemp.num,32) ] ]
      if (%ctemp.num > 1) { dec %ctemp.num | goto loop }
      dispa
    }
  }
  else {
    set %ctemp.key %crypt.key. [ $+ [ $1 ] ]
    if (%ctemp.key == $null) dispa No key for %col.target $+ $1 $+  has been set
    else dispa Key for %col.target $+ $1 $+  is %col.info1 $+ %ctemp.key
  }
  unset %ctemp.*
}
alias delkey {
  if ($1 == $null) { dispa Usage: /delkey nick/#channel | halt }
  set %ctemp.key %crypt.key. [ $+ [ $1 ] ]
  if (%ctemp.key == $null) dispa No key for %col.target $+ $1 $+  has been set
  else {
    set %crypt.key. [ $+ [ $1 ] ]
    set %crypt.keys $remtok(%crypt.keys,$1,32)
    dispa Key for %col.target $+ $1 $+  has been cleared
  }
  unset %ctemp.*
}
alias clearkeys {
  if (Y !isin $$?="Really clear ALL IRCrypt keys?") return
  unset %crypt.key.* %crypt.keys
  dispa All IRCrypt keys cleared.
}
; -----------------------------------------------------
; Encoding
; -----------------------------------------------------
alias enc {
  if ($1 == $null) { dispa Usage: /enc text | halt }
  if ($len($1-) > 250) _error Please type a shorter message, the encryption routine is limited to 250 characters for speed considerations
  if (($chr(32) isin $active) || ($left($active,1) == @)) _error Use /enc in a channel, query, or chat, please
  if ($left($active,1) == =) set %ctemp.key %crypt.key. [ $+ [ $remove($active,=) ] ]
  else set %ctemp.key %crypt.key. [ $+ [ $active ] ]
  if (%ctemp.key == $null) _error No key has been defined for this window! Use /key to define a key. (and make sure the target knows it.)
  set %ctemp.len $len(%ctemp.key)
  set %ctemp.len1 $int($calc(%ctemp.len / 3))
  set %ctemp.len2 %ctemp.len1
  set %ctemp.len3 %ctemp.len1
  if ($calc(%ctemp.len % 3) > 0) inc %ctemp.len1
  if ($calc(%ctemp.len % 3) > 1) inc %ctemp.len2
  _enc2 %ctemp.len1 %ctemp.len2 %ctemp.len3 $mid(%ctemp.key,1,%ctemp.len1) $mid(%ctemp.key,$calc(%ctemp.len1 + 1),%ctemp.len2) $mid(%ctemp.key,$calc(%ctemp.len2 + %ctemp.len1 + 1),%ctemp.len3) $replace($1-,$chr(32),)
}
alias -l _enc2 {
  bset &cur 1 1
  bset &cur 2 1
  bset &cur 3 1
  bset &cur 4 1
  unset %ctemp.out
  :loop
  bset &cur 5 $calc($asc($mid($7-,$bvar(&cur,4),1)) + $asc($mid($4,$bvar(&cur,1),1)) + $bvar(&cur,4))
  bset &cur 1 $calc($bvar(&cur,1) + 1)
  if ($bvar(&cur,1) > $1) bset &cur 1 1
  if ($calc($bvar(&cur,4) % 2) == 0) {
    bset &cur 5 $calc($bvar(&cur,5) + $asc($mid($5,$bvar(&cur,2),1)))
    bset &cur 2 $calc($bvar(&cur,2) + 1)
    if ($bvar(&cur,2) > $2) bset &cur 2 1
  }
  if ($calc($bvar(&cur,4) % 3) == 0) {
    bset &cur 5 $calc($bvar(&cur,5) + $asc($mid($6,$bvar(&cur,3),1)))
    bset &cur 3 $calc($bvar(&cur,3) + 1)
    if ($bvar(&cur,3) > $3) bset &cur 3 1
  }
  if ($bvar(&cur,5) > 33) set %ctemp.out %ctemp.out $+ $chr($bvar(&cur,5))
  else set %ctemp.out %ctemp.out $+ ! $+ $chr($calc($bvar(&cur,5) + 64))
  bset &cur 4 $calc($bvar(&cur,4) + 1)
  if ($bvar(&cur,4) <= $len($7-)) goto loop
  if ((%crypt.ctcpout) && ($chan($active) != $active) && (= !isin $active)) .raw NOTICE $active : $+ $chr(1) $+ /¢/ %ctemp.out $+ $chr(1)
  elseif ((%crypt.hideout) && (= !isin $active)) .raw PRIVMSG $active :/¢/ %ctemp.out
  else msg $active /¢/ %ctemp.out
  echo -ai2 ‹: $+ $me $+ :› $7-
  unset %ctemp.*
}
alias encrypt enc $1-
; -----------------------------------------------------
; "Automatic" encoding
; -----------------------------------------------------
on 1:input:*:{
  if ($left($1,1) != %crypt.prefix) return
  if (($chr(32) isin $active) || ($left($active,1) == @)) return
  if (($len($1) == 1) && ($2 == $null)) return
  enc $mid($1,2,$len($1)) $2- | halt
}
; -----------------------------------------------------
; Decoding
; -----------------------------------------------------
alias decrypt {
  if ($2 == $null) { dispa Usage: /decrypt source text | halt }
  set %ctemp.key %crypt.key. [ $+ [ $1 ] ]
  if (%ctemp.key == $null) {
    if ($3 == !) return
    else _error No key has been defined for  $+ $1 $+ ! Use /key to define a key. (and make sure its the same one as the sender.)
  }
  set %ctemp.len $len(%ctemp.key)
  set %ctemp.len1 $int($calc(%ctemp.len / 3))
  set %ctemp.len2 %ctemp.len1
  set %ctemp.len3 %ctemp.len1
  if ($calc(%ctemp.len % 3) > 0) inc %ctemp.len1
  if ($calc(%ctemp.len % 3) > 1) inc %ctemp.len2
  _decr2 %ctemp.len1 %ctemp.len2 %ctemp.len3 $mid(%ctemp.key,1,%ctemp.len1) $mid(%ctemp.key,$calc(%ctemp.len1 + 1),%ctemp.len2) $mid(%ctemp.key,$calc(%ctemp.len2 + %ctemp.len1 + 1),%ctemp.len3) $2-3
  return $result
}
alias -l _decr2 {
  bset &cur 1 1
  bset &cur 2 1
  bset &cur 3 1
  bset &cur 4 1
  unset %ctemp.out
  set %ctemp.pos 1
  :loop
  if ($mid($7,%ctemp.pos,1) == !) { inc %ctemp.pos | bset &cur 5 $calc($asc($mid($7,%ctemp.pos,1)) - 64 - $asc($mid($4,$bvar(&cur,1),1)) - $bvar(&cur,4)) }
  else bset &cur 5 $calc($asc($mid($7,%ctemp.pos,1)) - $asc($mid($4,$bvar(&cur,1),1)) - $bvar(&cur,4))
  bset &cur 1 $calc($bvar(&cur,1) + 1)
  if ($bvar(&cur,1) > $1) bset &cur 1 1
  if ($calc($bvar(&cur,4) % 2) == 0) {
    bset &cur 5 $calc($bvar(&cur,5) - $asc($mid($5,$bvar(&cur,2),1)))
    bset &cur 2 $calc($bvar(&cur,2) + 1)
    if ($bvar(&cur,2) > $2) bset &cur 2 1
  }
  if ($calc($bvar(&cur,4) % 3) == 0) {
    bset &cur 5 $calc($bvar(&cur,5) - $asc($mid($6,$bvar(&cur,3),1)))
    bset &cur 3 $calc($bvar(&cur,3) + 1)
    if ($bvar(&cur,3) > $3) bset &cur 3 1
  }
  set %ctemp.out %ctemp.out $+ $chr($bvar(&cur,5))
  bset &cur 4 $calc($bvar(&cur,4) + 1)
  inc %ctemp.pos
  if (%ctemp.pos <= $len($7)) goto loop
  if ($8 == !) return $replace(%ctemp.out,,$chr(32))
  disp Decrypted- $replace(%ctemp.out,,$chr(32))
  unset %ctemp.*
}
on 1:ctcpreply:/¢/*:{
  if (%crypt.hold) return
  _icfldc
  if ($chan != $null) {
    if (($2 == $null) || ($3 != $null)) set %ctemp.echo 4Erroneous encryption ( $+ $1- $+ )
    else {
      set %ctemp.echo $decrypt($chan,$2,!)
      if (%ctemp.echo == $null) set %ctemp.echo $decrypt($nick,$2,!)
      if (%ctemp.echo == $null) { if (%crypt.warned) { uinset %ctemp.* | return } | set -u20 %crypt.warned $true | set %ctemp.echo 4No known decryption key for channel  $+ $chan $+  or user  $+ $nick $+  ( $+ $1- $+ ) }
      else set %ctemp.echo ‹ $+ $nick $+ › %ctemp.echo
    }
    echo -i2 $chan %ctemp.echo
  }
  else {
    if (($2 == $null) || ($3 != $null)) set %ctemp.echo 4Erroneous encryption ( $+ $1- $+ )
    else {
      set %ctemp.echo $decrypt($nick,$2,!)
      if (%ctemp.echo == $null) { if (%crypt.warned) { unset %ctemp.* | return } | set -u20 %crypt.warned $true | set %ctemp.echo 4No known decryption key for user  $+ $nick $+  ( $+ $1- $+ ) }
      else set %ctemp.echo ‹ $+ $nick $+ › %ctemp.echo
    }
    if ($query($nick) != $nick) q $nick
    echo -i2 $nick %ctemp.echo
  }
  unset %ctemp.*
  halt
}
on 1:text:/¢/ *:?:{
  if ((%crypt.hold) || ($2 == $null) || ($3 != $null)) return
  else {
    _icfldc
    set %ctemp.echo $decrypt($chan,$2,!)
    if (%ctemp.echo == $null) set %ctemp.echo $decrypt($nick,$2,!)
    if (%ctemp.echo == $null) { if (%crypt.warned) { unset %ctemp.* | return } | set -u20 %crypt.warned $true | set %ctemp.echo 4No known decryption key for channel  $+ $chan $+  or user  $+ $nick }
    else set %ctemp.echo ‹ $+ $nick $+ › %ctemp.echo
    echo -i2 $nick %ctemp.echo
  }
  unset %ctemp.*
}
on 1:text:/¢/ *:#:{
  if ((%crypt.hold) || ($2 == $null) || ($3 != $null)) return
  else {
    _icfldc
    set %ctemp.echo $decrypt($chan,$2,!)
    if (%ctemp.echo == $null) { if (%crypt.warned) { unset %ctemp.* | return } | set -u20 %crypt.warned $true | set %ctemp.echo 4No known decryption key for channel  $+ $chan }
    else set %ctemp.echo ‹ $+ $nick $+ › %ctemp.echo
    echo -i2 $chan %ctemp.echo
  }
  unset %ctemp.*
}
on 1:chat:/¢/ *:{
  if ((%crypt.hold) || ($2 == $null) || ($3 != $null)) return
  else {
    _icfldc
    set %ctemp.echo $decrypt($nick,$2,!)
    if (%ctemp.echo == $null) { if (%crypt.warned) { unset %ctemp.* | return } | set -u20 %crypt.warned $true | set %ctemp.echo 4No known decryption key for user  $+ $nick }
    else set %ctemp.echo ‹ $+ $nick $+ › %ctemp.echo
    echo -i2 =$nick %ctemp.echo
  }
  unset %ctemp.*
}
; -----------------------------------------------------
; Flood check
; -----------------------------------------------------
alias -l _icfldc {
  if (%crypt.fcheck) {
    set -u15 %crypt.flood $calc( [ %crypt.flood ] + 1)
    if (%crypt.flood > 8) {
      set -u30 %crypt.hold $true
      disps 4Ignoring (not decrypting) IRCrypt encryption for 30 seconds due to flood. (8 or more encryptions in 15 seconds)
    }
  }
}
on 1:connect:unset %crypt.flood %crypt.hold %crypt.warned %ctemp.*
on 1:start:unset %ctemp.* %crypt.give %crypt.take %crypt.req.*
; -----------------------------------------------------
; Key distribution
; -----------------------------------------------------
ctcp 1:CRYPTKEY:{
  if (($2 != ASK) || ($3 == $null) || ($4 != $null)) return
  if (($left($3,1) !isin +&#) && ($3 != $nick)) return
  unset %ctemp.give
  if (%crypt.giveall) set %ctemp.give $true
  elseif ($ulevel > %crypt.givelevel) set %ctemp.give $true
  elseif ((%crypt.givenotify) && ($nick isnotify)) set %ctemp.give $true
  set %ctemp.key %crypt.key. [ $+ [ $3 ] ]
  disps Encryption key request from  $+ $nick $+  for  $+ $3 $+  key
  if (%ctemp.key == $null) {
    disps Request ignored- you have not defined this key yet.
    unset %ctemp.* | halt
  }
  if (%ctemp.give != $true) { set %crypt.give $nick : $+ $chr(1) $+ $1 GIVE $3 %ctemp.key $+ $chr(1) | disps Encryption key request not automatically filled- Type /givekey to send the user the key. }
  else { .raw NOTICE $nick : $+ $chr(1) $+ $1 GIVE $3 %ctemp.key $+ $chr(1) | disps Encryption key request automatically filled. }
  unset %ctemp.*
  halt
}
alias givekey {
  if ($1 != $null) { sendkey $1- | return }
  if (%crypt.give != $null) {
    dispa Encryption key request filled.
    .raw NOTICE %crypt.give
  }
  unset %crypt.give
}
on 1:ctcpreply:CRYPTKEY GIVE & &:{
  if (($left($3,1) !isin +&#) && ($3 != $me)) halt
  unset %ctemp.give
  if (%crypt.req. [ $+ [ $nick ] ] == $3) { set %crypt.req. [ $+ [ $nick ] ] | set %ctemp.give $true }
  elseif (%crypt.req. [ $+ [ $comchan($nick,1) ] ] == $3) set %ctemp.give $true
  elseif (%crypt.acceptall) set %ctemp.give $true
  elseif ($ulevel > %crypt.acceptlevel) set %ctemp.give $true
  elseif ((%crypt.acceptnotify) && ($nick isnotify)) set %ctemp.give $true
  disps Encryption key offer from  $+ $nick $+  for  $+ $3 $+  ( $+ $4 $+ )
  if (%ctemp.give != $true) {
    if ($left($3,1) isin +&#) disps Encryption key offer not automatically accepted- Type /takekey to accept the offered channel key.
    else disps Encryption key offer not automatically accepted- Type /takekey to accept the user's private key.
    if ($3 == $me) set %crypt.take $nick $4
    else set %crypt.take $3 $4
    unset %ctemp.*
    halt
  }
  disps Encryption key stored in database.
  if ($3 == $me) set %crypt.key. [ $+ [ $nick ] ] $4
  else set %crypt.key. [ $+ [ $3 ] ] $4
  unset %ctemp.*
  halt
}
alias takekey {
  if (%crypt.take != $null) {
    dispa Encryption key stored in database.
    set %crypt.key. [ $+ [ $gettok(%crypt.take,1,32) ] ] $gettok(%crypt.take,2,32)
  }
  unset %crypt.take
}
alias askkey {
  if ($1 == $null) { dispa Usage: /askkey nickname [channel] | halt }
  if ($2 == $null) {
    ctcp $1 CRYPTKEY ASK $me
    set %crypt.req. [ $+ [ $1 ] ] $me
  }
  else {
    ctcp $1 CRYPTKEY ASK $2
    set %crypt.req. [ $+ [ $1 ] ] $2
  }
}
alias sendkey {
  if ($1 == $null) { dispa Usage: /sendkey nickname/chan [channel] | halt }
  if ($2 == $null) set %ctemp.targ $1
  else set %ctemp.targ $2
  set %ctemp.key %crypt.key. [ $+ [ %ctemp.targ ] ]
  if (%ctemp.key == $null) _error No matching key has been defined! Use /key to define a key.
  ctcpreply $1 CRYPTKEY GIVE %ctemp.targ %ctemp.key
  unset %ctemp.*
}
; -----------------------------------------------------
; Help
; -----------------------------------------------------
menu @Crypt {
  Close window:window -c @Crypt
}
alias ircrypt crypt
alias crypt {
  window -c @Crypt
  window -l @Crypt @Crypt Arial 14
  titlebar @Crypt - Help on using IRCrypt (Standdard version)
  aline 12 @Crypt How IRCrypt works-
  aline @Crypt $chr(160) The encryption is key-based. The keys can be any length of 3 characters or more, and contain any
  aline @Crypt $chr(160) character except spaces. Longer keys are generally more secure, and the entire key is used in encrypting
  aline @Crypt $chr(160) messages, unless the key is longer than the message. IRCrypt uses a relatively complex, hard-to-break
  aline @Crypt $chr(160) scheme, with an infinite variety of keys. This is unlike other mIRC encryption scripts which have easy to
  aline @Crypt $chr(160) crack schemes based on a limited number of keys. (rarely more than 256 possibilities.)
  aline @Crypt $chr(160)
  aline 12 @Crypt Popups-
  aline @Crypt $chr(160) Popups have been added to the channel and query/chat popups to ease use of IRCrypt. They
  aline @Crypt $chr(160) can be used instead of the aliases mentioned below- any function listed below can be performed
  aline @Crypt $chr(160) via popups as well. Please read the rest of this help before using them though.
  aline @Crypt $chr(160)
  aline 12 @Crypt Quick start-
  aline @Crypt $chr(160) The simplest way to start using IRCrypt is to select the popup "Set key", enter a key, then select
  aline @Crypt $chr(160) the popup "Send key" to send the key to the target. Now you can use /enc to encode text for
  aline @Crypt $chr(160) that window. (or prefix your text with a ~, the default encryption prefix)
  aline @Crypt $chr(160)
  aline 12 @Crypt How to define keys-
  aline @Crypt $chr(160) To set a key for private conversation, type /key nickname key. Any encrypted text you send to this
  aline @Crypt $chr(160) nickname will now be encrypted using that key, and any private text from this user will be decrypted
  aline @Crypt $chr(160) with this key.
  aline @Crypt $chr(160)
  aline @Crypt $chr(160) To set a key for channel encryption, type /key #channel key. All encrypted text send to and
  aline @Crypt $chr(160) received from that channel will be encoded/decoded using that key.
  aline @Crypt $chr(160)
  aline 12 @Crypt How to give your keys to others-
  aline @Crypt $chr(160) To tell a user what key you are using to encrypt their private text, type /sendkey nickname. Of
  aline @Crypt $chr(160) course, they must be using IRCrypt to make any use of this key. To tell a user what key you are
  aline @Crypt $chr(160) using in a certain channel, type /sendkey nickname #channel. To tell an entire channel what
  aline @Crypt $chr(160) key you are using for that channel, type /sendkey #channel. If you are going to use IRCrypt in a
  aline @Crypt $chr(160) channel, all the users in that channel should agree on a key ahead of time and not change it.
  aline @Crypt $chr(160)
  aline @Crypt $chr(160) When someone sends you a key, you may or may not automatically accept the key, depending on
  aline @Crypt $chr(160) your settings. If you do not automatically accept the key, you will be noted of this and you may, as
  aline @Crypt $chr(160) the note will say, type /takekey to accept the key.
  aline @Crypt $chr(160)
  aline 12 @Crypt How to request keys from others-
  aline @Crypt $chr(160) To ask a user what key they are using to encrypt private text to you, type /askkey nickname.
  aline @Crypt $chr(160) When (if) they reply, you will automatically accept the key. To ask a user what key they are using
  aline @Crypt $chr(160) to encrypt text in a certain channel, type /askkey nickname #channel. When (if) they reply, you
  aline @Crypt $chr(160) will automatically accept that key and use it for that channel.
  aline @Crypt $chr(160)
  aline @Crypt $chr(160) When someone requests a key from you, you may or may not automatically return the requested key,
  aline @Crypt $chr(160) depending on your settings. If you do not automatically send the key, you will be noted of this and you
  aline @Crypt $chr(160) will be told to type /givekey to send the requested key.
  aline @Crypt $chr(160)
  aline 12 @Crypt How to encode text- (finally!)
  aline @Crypt $chr(160) Simply type /enc message to encode in the proper window. The key for that channel or user will
  aline @Crypt $chr(160) automatically be looked up and used. The text will be encrypted and sent to the window. You can
  aline @Crypt $chr(160) also simply prefix your text with a ~, which will encrypt it. This character can be changed in the
  aline @Crypt $chr(160) IRCrypt configuration.
  aline @Crypt $chr(160)
  aline 12 @Crypt How to decode text-
  aline @Crypt $chr(160) If you have the (proper) key for a channel or user, text they send you will be automatically decoded.
  aline @Crypt $chr(160) If you have an improper key, the text will simply appear garbled. Once you and your friends agree on
  aline @Crypt $chr(160) a key, you should probably not change them needlessly, to prevent having an incorrect key.
  aline @Crypt $chr(160)
  aline 12 @Crypt Manual decoding-
  aline @Crypt $chr(160) If for some reason you need to manually decode encrypted text, type /decrypt from encryptedmessage.
  aline @Crypt $chr(160) "from" is the #channel or nickname that the text is from, and is used to locate the proper key.
  aline @Crypt $chr(160)
  aline 12 @Crypt Viewing keys-
  aline @Crypt $chr(160) If you need to view keys in your database, type /viewkey nickname/#channel to view the keys for
  aline @Crypt $chr(160) a nickname or channel, or type /viewkey to view all keys.
  aline @Crypt $chr(160)
  aline 12 @Crypt Configuration options-
  aline @Crypt $chr(160) Type /cryptcfg (or use the popups) to access IRCrypt configuration. Here you can define who you
  aline @Crypt $chr(160) are willing to automatically accept keys from/automatically send requested keys to, and also you can
  aline @Crypt $chr(160) choose whether or not you wish to see the encoded version of the text you type. (normally the
  aline @Crypt $chr(160) encrypted version is hidden and only your original message is displayed in your window.) Also, you
  aline @Crypt $chr(160) can define whether to use CTCP replies when sending private encrypted messages. (instead of
  aline @Crypt $chr(160) standard text.) The advantage of CTCP replies is that the receipient does not see both the encrypted
  aline @Crypt $chr(160) junk AND the decoded text- only the decoded text is shown. With standard text, the "junk" is shown
  aline @Crypt $chr(160) as well. (it is recommended that you leave this option on.) You can also disable the flood check if
  aline @Crypt $chr(160) needed.
  aline @Crypt $chr(160)
  aline @Crypt $chr(160) You can also define a prefix character that tells IRCrypt to encrypt that line of text without having to
  aline @Crypt $chr(160) use a popup or the /enc command. This defaults to ~, for example "~this text will be encrypted".
  aline @Crypt $chr(160)
  aline 12 @Crypt Note on use in DCC chats-
  aline @Crypt $chr(160) Neither incoming nor outgoing text can be hidden when using IRCrypt in a DCC chat.
  aline @Crypt $chr(160)
  aline 12 @Crypt Note on Peace and Protection-
  aline @Crypt $chr(160) You can download a P&P-specific version of IRCrypt at the P&P homepage.
  aline @Crypt $chr(160) (http://pairc.com/pnp/)
}
; -----------------------------------------------------
; Popups
; -----------------------------------------------------
menu channel {
  -
  IRCrypt
  .Encrypt text...:enc $$?="Text to encrypt?"
  .-
  .Keys
  ..Set key for channel...:key # $$?="New key for channel?"
  ..View key for channel:viewkey #
  ..Send key to channel:sendkey #
  ..-
  ..Ask for key
  ...Channel key:askkey # #
  ...Your key:askkey #
  ..-
  ..Clear ALL keys:clearkeys
  ..View ALL keys:viewkey
  .-
  .Help...:crypt
  .Configure...:cryptcfg
  .-
  .Unload...:cryptun
}
menu query {
  -
  IRCrypt
  .Encrypt text...:enc $$?="Text to encrypt?"
  .-
  .Keys
  ..Set key for user...:key $1 $$?="New key for user?"
  ..View key for user:viewkey $1
  ..Send key to user:sendkey $1
  ..-
  ..Trade keys (send + ask for):sendkey $1 | askkey $1
  ..-
  ..Ask for key
  ...Your key:askkey $1
  ...Channel key
  ....$comchan($active,1):askkey $1 $comchan($1,1)
  ....$comchan($active,2):askkey $1 $comchan($1,2)
  ....$comchan($active,3):askkey $1 $comchan($1,3)
  ....-
  ....Other...:askkey $1 $$?="Channel to ask for key from?"
  .-
  .Help...:crypt
  .Configure...:cryptcfg
  .-
  .Unload...:cryptun
}
; -----------------------------------------------------
; Configuration
; -----------------------------------------------------
menu @IRCrypt {
  dclick /_ccdbc
  Close window:window -c @IRCrypt
}
alias ircryptcfg cryptcfg
alias cryptcfg {
  window -c @IRCrypt
  window -l @IRCrypt @IRCrypt Arial 15
  titlebar @IRCrypt configuration
  set %ctemp.line 1
  :loop
  _ccfgl %ctemp.line
  inc %ctemp.line
  if (%ctemp.line < 18) goto loop
  unset %ctemp.line
}
alias -l _tf2o if ($1) return On | return Off
alias -l _ccfgl {
  if ($1 == 1) rline @IRCrypt 1 - Double click on an option to toggle or change it -
  elseif ($1 == 3) rline @IRCrypt 3 When you are sent a key, auto-accept from-
  elseif ($1 == 4) rline @IRCrypt 4 • People on notify list - $_tf2o(%crypt.acceptnotify)
  elseif ($1 == 5) rline @IRCrypt 5 • People on user list ABOVE level - %crypt.acceptlevel
  elseif ($1 == 6) rline @IRCrypt 6 • Anyone (not recommended) - $_tf2o(%crypt.acceptall)
  elseif ($1 == 8) rline @IRCrypt 8 When you are asked for a key, auto-send to-
  elseif ($1 == 9) rline @IRCrypt 9 • People on notify list - $_tf2o(%crypt.givenotify)
  elseif ($1 == 10) rline @IRCrypt 10 • People on user list ABOVE level - %crypt.givelevel
  elseif ($1 == 11) rline @IRCrypt 11 • Anyone (not recommended) - $_tf2o(%crypt.giveall)
  elseif ($1 == 13) rline @IRCrypt 13 Hide encrypted version of text that you send - $_tf2o(%crypt.hideout)
  elseif ($1 == 14) rline @IRCrypt 14 Send private encryption as CTCP reply (recommended) - $_tf2o(%crypt.ctcpout)
  elseif ($1 == 15) rline @IRCrypt 15 Perform flood check? (8+ encrypted messages in 15 seconds) - $_tf2o(%crypt.fcheck)
  elseif ($1 == 17) rline @IRCrypt 17 Prefix character to use encryption - %crypt.prefix
  else rline @IRCrypt $1 $chr(160)
}
alias -l _not if ($1) return $false | return $true
alias -l _ccdbc {
  set %ctemp.ln $sline(@IRCrypt,1).ln
  if (%ctemp.ln == 4) set %crypt.acceptnotify $_not(%crypt.acceptnotify)
  elseif (%ctemp.ln == 9) set %crypt.givenotify $_not(%crypt.givenotify)
  elseif (%ctemp.ln == 6) set %crypt.acceptall $_not(%crypt.acceptall)
  elseif (%ctemp.ln == 11) set %crypt.giveall $_not(%crypt.giveall)
  elseif (%ctemp.ln == 13) set %crypt.hideout $_not(%crypt.hideout)
  elseif (%ctemp.ln == 14) set %crypt.ctcpout $_not(%crypt.ctcpout)
  elseif (%ctemp.ln == 15) set %crypt.fcheck $_not(%crypt.fcheck)
  elseif (%ctemp.ln == 5) set %crypt.acceptlevel $$?="Require people on user list to be above what level?"
  elseif (%ctemp.ln == 10) set %crypt.givelevel $$?="Require people on user list to be above what level?"
  elseif (%ctemp.ln == 17) {
    set %ctemp.token $?="Automatically encrypt if first character is what?"
    if (%ctemp.token == $null) set %crypt.prefix (none)
    else set %crypt.prefix %ctemp.token
  }
  _ccfgl %ctemp.ln
  unset %ctemp.*
}
; -----------------------------------------------------
; Default settings and startup
; -----------------------------------------------------
on 1:load:{
  disps IRCrypt loaded. Type /crypt for help or use the popups in channel/query windows.
  disps Type /cryptun (or use popups) to unload IRCrypt.
  unset %crypt.flood %crypt.hold %crypt.warned %ctemp.* %crypt.give %crypt.take %crypt.req.*
  if (%crypt.givelevel == $null) {
    set %crypt.acceptnotify $true
    set %crypt.givenotify $true
    set %crypt.acceptall $false
    set %crypt.giveall $false
    set %crypt.acceptlevel 2
    set %crypt.givelevel 2
    set %crypt.hideout $false
    set %crypt.ctcpout $true
    set %crypt.fcheck $true
    set %crypt.prefix ~
  }
}
; -----------------------------------------------------
; Unloading
; -----------------------------------------------------
alias cryptun {
  if (Y !isin $$?="Unload IRCrypt?") halt
  unset %crypt.* %ctemp.*
  disps IRCrypt unloaded.
  unload -rs ircryptn.mrc | halt
}