All pastes #948061 Raw Edit

Blowfish Encryption for mIRC

public text v1 · immutable
·published 2008-03-18 21:38 UTC
rendered paste body
on *:input:#3nvisi0n:{ var %win_t = $window($active).type
  if (%win_t == chat) {
    if ($chat($nick).status != active) goto encbeep
  }
  elseif ((%win_t == channel) || (%win_t == query)) {

    if (!$server) bf.halt /enc: Not connected to server
  }
  else goto encbeep | msg $active +OK $bf.ucom(enc,$1-)
  echo -atlbfmr $bf.pre $1- | halt
  :encbeep | beep 1
}
;----------------------------------------------------------
; Blowfish Encryption for mIRC - v2.2 (June 11th, 2007)
;----------------------------------------------------------
;
; This little script allows you to send and receive
; encrypted messages in mIRC. It makes use of the popular
; Blowfish symmetric encryption system, and requires a
; certain Blowfish DLL file.
;
; In order to decrypt your encrypted messages, one must
; know the unique keyword you use. Without the right
; keyword, it is virtually impossible to decrypt the
; messages (it could take years).
;
; Usage: /enc <message>
;
; The above sends an encrypted message. Such messages can
; be sent and received in channel, query and DCC chat
; windows.
;
; In addition, /encr <plaintext> can be used to manually
; encrypt plaintext, and /decr <ciphertext> can be used to
; decrypt Blowfish ciphertext. Results are printed locally.
;
; The keyword used for encryption and decryption is
; specified in the configuration section below. The file
; "blowfish.dll" must be in the same directory as this
; script. This script is compatible with the FiSH add-on.
;
; Credits:
;  - Blowfish algorithm: Bruce Schneier
;  - DLL for mIRC (blowfish.dll): Gustavo Picon
;  - mIRC script (blowfish.mrc): Rotem E. <rotem@live.com>
;
alias -l bf.conf {
  ;
  ;--------------------------------------------------------
  ; Configuration
  ;--------------------------------------------------------
  ;
  ; KEYWORD: Set this to the unique keyword that you wish
  ; to use (modify the value after the equal sign). The
  ; keyword is limited to 72 characters and must not
  ; contain spaces. It is recommended to use a keyword of
  ; at least 16 characters for maximum security.
  ;
  var %KEYWORD = 3nvisi0n

  ; DECRYPT: By default, encrypted messages are decrypted
  ; automatically in channel, query and DCC chat windows.
  ; You can disable auto-decryption by changing this
  ; setting to "no". Change back to "yes" to re-enable.
  ;
  var %DECRYPT = yes

  ; -------------------------------------------------------
  ;  End of configuration. Code ahead.
  ; -------------------------------------------------------


  %decrypt = $replace(%decrypt,yes,$true,no,$false)
  return $($+(%,$$1),2)
}

; user commands
alias enc {
  var %win_t = $window($active).type
  if (%win_t == chat) {
    if ($chat($nick).status != active) goto encbeep
  }
  elseif ((%win_t == channel) || (%win_t == query)) {
    if (!$server) bf.halt /enc: Not connected to server
  }
  else goto encbeep | msg $active +OK $bf.ucom(enc,$1-)
  echo -atlbfmr $bf.pre $1- | halt
  :encbeep | beep 1
}
alias encr echo -a encr: $bf.ucom(encr,$1-)
alias decr echo -a decr: $bf.ucom(decr,$1-)

; perform enc/dec for user commands. return the result or
; echo & halt if error ($1 = enc/encr/decr, $2 = string)
alias -l bf.ucom {
  if (($1 === enc) || ($1 === encr)) var %proc = Encrypt
  elseif ($1 === decr) var %proc = Decrypt | else halt
  if ($bf.errchk($2)) bf.halt $+(/,$1,:) $v1
  var %res = $bf.calldll(%proc,$2)
  if (%res == $null) bf.halt $+(/,$1,:) $+(%proc,ion) error
  return %res
}
; error handler for user commands
alias -l bf.halt {
  var %arg = $iif(($active == Status Window),-ace,-ac)
  echo %arg info * $$1- | halt
}

; event handler
on *:CHAT:+OK *:bf.autodec =$nick $$2-
on *:TEXT:+OK *:*:bf.autodec $iif($chan,$chan,$nick) $$2-
alias -l bf.autodec {
  if ((!$bf.conf(DECRYPT)) || ($bf.errchk($2-))) return
  if ($bf.calldll(Decrypt,$2-) == $null) return
  if ($v1 == $2-) return | echo -tlbfmr $1 $bf.pre $v1
}

; general identifiers
alias -l bf.pre return $+(,$colour(action),>>)
alias -l bf.dll return $+(",$scriptdir,blowfish.dll,")
; preliminary error checking ($1 = string to enc/dec)
; returns error message or $null if none
alias -l bf.errchk {
  if ($1 == $null) return Insufficient parameters
  if (!$isfile($bf.dll)) {
    return Blowfish DLL file not found ( $+ $bf.dll $+ )
  }
  if ($numtok($bf.conf(KEYWORD),32) != 1) {
    return Erroneous keyword (unset or includes spaces)
  }
  return $null
}
; enc/dec, returns result string or $null if DLL error
; ($1 = Encrypt/Decrypt, $2 = string)
alias -l bf.calldll {
  var %str = $2
  if (($1 == Decrypt) && ($calc($len(%str) % 12))) {
    %str = $left(%str,$+(-,$v1))
  }
  %str = $dll($bf.dll,$1,$bf.conf(KEYWORD) %str)
  if ($gettok(%str,1,32) != +OK) return $null
  return $gettok(%str,2-,32)
}