mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 24
D
dylan Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Dec 2002
Posts: 24
I've got a small script written in Perl that I'm trying to convert into a mIRC script. I'm having a bit of a hard time and I'm wondering if anyone out there who can script in both Perl and mIRC can help me out. The code is:

sub decode {
my $text = $_[0];
my $key = 'secretkey';
my $response = '';
my($i, $j, $num, $result);
my($text_len) = length($text);
my($key_len) = length($key);
for ($i = $text_len - 1; $i >= 0; --$i) {
$num = ord(chop($text));
if ($num == 127) { $num = 58 }
$num -= 33;
for ($j = $i; $j < $key_len; $j += $text_len) {
$num -= ord(substr($key, $j, 1)) + $key_len;
}
$num = $num % 95 + 33;
$result .= pack("c", $num);
}
return($result);
}

Is it possible to rewrite this in the mIRC scripting language? Or even make a DLL from it? If not, thanks for your time.

Last edited by dylan; 13/06/03 10:39 PM.

-- dylan
Joined: Jun 2003
Posts: 6
K
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
K
Joined: Jun 2003
Posts: 6
It sure is possible...but its unlikely you will get anyone to paste code smile I would help you out...if you posted the encrypted part $_[0] and the $result so I can check my code and make sure it works correctly.

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
This should work:
Code:
alias perl_decode {
  var %text = $1-
  var %key = secretkey
  var %response
  var %i, %j, %num ,%result
  var %text_len = $len(%text)
  var %key_len = $len(%key)
  %i = $calc(%text_len -1)
  while (%i &gt;= 0) {
    var %chop = $right(%text,1)
    %text = $left(%text,-1)
    var %num = $asc(%chop)
    if (%num == 127) { %num = 58 }
    %num = $calc(%num - 33)
    %j = %i
    while (%j &lt; %key_len) {
      %num = $calc(%num - ($asc($mid(%key,$calc(%j +1),1)) + %key_len))
      inc %j %text_len
    }
    %num = $calc($perl_modulus(%num,95) + 33)

    .echo -a %num
    %result = %result $+ $chr(%num)
    dec %i
  }
  return %result
}

;Perl has a very odd way of handling modulus
alias -l perl_modulus {
  if ($1 &lt; 0) {
    var %i = 1
    while ($calc(%i * $2) &lt;= $abs($1)) {
      inc %i
    }
    var %m = $calc(%i * $2)
    return $calc(%m - $abs($1))
  }
  return $calc($1 % $2)
}


I renamed it $perl_decode because mIRC already has an identifier called $decode. It seems to work perfectly. The biggest issue with the code (if you tried to convert it) was that Perl's % operator behaves differently than well... every other % operator I've ever seen. I think I got it working though, it seemed to work when I compared the output of some of some runs with the perl command, but if it doesn't, let me know.

Joined: Dec 2002
Posts: 24
D
dylan Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Dec 2002
Posts: 24
Thank you so much, codemastr, that worked great. I really appreciate it! smile


-- dylan
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Why on earth would you use a loop in the $perl_modulus alias? This would be considered inefficient even for a C program; it's unacceptably slow for mirc. Considering that the $perl_decode alias already does quite a lot of work, an optimized $perl_modulus is more than necessary.
Code:
alias perl_modulus {
  if $1 &lt; 0 { return $calc($int($calc($1 / $2 - 1)) * - $2 + $1) }
  return $calc($1 % $2)
}
I also got rid of the variable %m and $abs(), which made things even worse.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard