home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bx75p3.zip / doc / op-crypt.tcl < prev    next >
Text File  |  1999-02-23  |  1KB  |  54 lines

  1. if {![info exists blowfish_version]} {
  2.     putscr "You MUST load the blowfish encryption module prior to loading this!"
  3.     return 0
  4. }
  5.  
  6. set crypt_timeout 60
  7.  
  8. #borrowed from alltools.tcl
  9. proc randstring {count} {
  10.   set rs ""
  11.   for {set j 0} {$j < $count} {incr j} {
  12.      set x [rand 62]
  13.      append rs [string range "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" $x $x]
  14.   }
  15.   unset x
  16.   unset j
  17.   return $rs
  18. }
  19.  
  20. proc crop {n args} {
  21.     global cryptkeeper cryptlist crypt_timeout
  22.     if [onchan $n [_T]] {
  23.         if {![info exists cryptkeeper([string tolower $n])]} {
  24.             putscr "You must first set a pair of crypt keys before using this."
  25.             putscr "Try /addcrypt <nick> <key1> <key2>"
  26.             return 0
  27.         }
  28.         putserv "privmsg $n :crypt_op"
  29.         set cryptlist([string tolower $n]) [utimer $crypt_timeout "unset cryptlist([string tolower $n])"]
  30.     }
  31.     return 0
  32. }
  33.  
  34. bind msg -1 crypt_op crypt_response
  35.  
  36. proc crypt_response {n u h a} {
  37.     global cryptkeeper cryptlist
  38.     if {![info exists cryptlist([string tolower $n])]} {
  39.         putscr "$n requesting UNAUTHORIZED crypt verification!"
  40.         return 1
  41.     } {
  42.         unset cryptlist([string tolower $n])
  43.         putserv "privmsg $n :crypt_reply [encrypt [lindex $cryptkeeper([string tolower $n]) 1] [decrypt [lindex $cryptkeeper([string tolower $n]) 0] $a]]"
  44.     }
  45.     return 1
  46. }
  47.  
  48. proc addcrypt {n k1 k2 args} {
  49.     global cryptkeeper
  50.     set cryptkeeper([string tolower $n]) "$k1 $k2"
  51.     putscr "Added $n to the crypt keeper with keys $k1 and $k2."
  52. }
  53. return 0
  54.