All pastes #420655 Raw Edit

Something

public text v1 · immutable
·published 2007-04-02 09:48 UTC
rendered paste body
;Usage: /encrypt <on|off> [key] [MIMEcount]     Turns automatic encryption on or off and sets the key and mimecount
;Usage: $nitrous(string,key,mimecount)          Encrypts string using specified key and mimecount
;Usage: $nitrous(string,key,mimecount).dec      Decrypts string using specified key and mimecount
;NOTE: MIMEcount must *always* be less than KEY.
;Example: $nitrous(test,5,3)                    Returns E.#)5+4LZ13DE-C<Q+C17040S5"TY.B4E)S!&/3DQ5"1=8&!@8```
;Example: $nitrous(E.#)5+4LZ13DE-C<Q+C17040S5"TY.B4E)S!&/3DQ5"1=8&!@8```,5,3).decrypt Returns test
alias enc {
  if ( $1 == off ) {
    set %enc off
    echo $colour(info) -a * Encryption is now OFF
  }
  elseif ( $1 == on ) {
    if ( !$2 ) && ( !%k ) {
      echo $colour(info) -a * You must specify a key!
      halt
    }
    elseif ( !$3 ) && ( !%mc ) {
      echo $colour(info) -a * You must specify a MIME count!
      halt
    }
    set %k $2
    set %mc $3
    if ( %k < 1 ) || ( $chr(46) isin %k ) || ( %k !isnum ) {
      echo $colour(info) -a * Invalid Key
      unset %k
      halt
    }
    if ( %mc < %k ) || ( $chr(46) isin %mc ) || ( %mc !isnum ) {
      echo $colour(info) -a * Invalid MIME count
      unset %mc
      halt
    }
    set %enc on
    echo $colour(info) -a * Encryption is now ON, using  $+ %k $+  as key,  $+ %mc $+  as MIME count
  }
  else {
    echo $colour(info) -a * SYNTAX: /encrypt <on|off> [key] [MIME count]
  }
}
alias nitrous {
  if ( !$2 ) || ( !$3 ) || ( $2 !isnum ) || ( $3 !isnum ) {
    return $null
  }
  if ( !$prop ) {
    var %f = $1,%c = 1
    while ( %c <= $2 ) {
      %f = $encode(%f,$iif($3 // %c,m,u))
      inc %c
    }
    return %f
  }
  elseif ( $prop == dec ) || ( $prop == decrypt) {
    var %f = $1,%c = $2
    while (%c) {
      %f = $decode(%f,$iif($3 // %c,m,u))
      dec %c
    }
    return %f
  }
}
on *:input:*: {
  if ( %enc == on ) && ( $left($1,1) != $readini(mirc.ini,text,commandchar) ) {
    var %c = 1,%f = $1-
    while (%c <= %k) {
      %f = $encode(%f,$iif(%mc // %c,m,u))
      inc %c
    }
    msg $active $chr(384) %f
    halt
  }
}
on *:TEXT:*:*: {
  if ( $1 == $chr(384) ) {
    var %c = %k,%f = $2-
    while (%c) {
      %f = $decode(%f,$iif(%mc // %c,m,u))
      dec %c
    }
    if ( !$window(@decrypted) ) {
      window -n @decrypted
    }
    aline @decrypted  $+ $nick $+ : %ft
  }
}