Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- IRC::print "Loading llrcombs's Binary/ASCII converter script";
- #Replace a string without using RegExp.
- sub str_replace
- {
- my $search = shift;
- my $replace = shift;
- my $subject = shift;
- if (! defined $subject) { return -1; }
- my $count = shift;
- if (! defined $count) { $count = -1; }
- my ($i,$pos) = (0,0);
- while ( (my $idx = index( $subject, $search, $pos )) != -1 )
- {
- substr( $subject, $idx, length($search) ) = $replace;
- $pos=$idx+length($replace);
- if ($count>0 && ++$i>=$count) { last; }
- }
- return $subject;
- }
- sub convert_binary
- {
- my $query = shift;
- $l=(length $query)*8;@a=unpack "B$l",$query;
- $binary = "";
- foreach $line (@a){
- $binary = $binary.$line;
- }
- $binary = "$binary";
- $i = 0;
- $binary2 = "";
- foreach $digit (split(undef,$binary)){
- $i++;
- $binary2 = $binary2.$digit;
- if($i == 8){
- $binary2 = $binary2." ";
- $i = 0;
- }
- }
- IRC::print ("Sent binary: $query");
- if(length($binary2)>422){
- while(length($binary2)){
- $binary_432 = substr($binary2,0,422);
- $binary2 = substr($binary2,423);
- IRC::command ("/say $binary_432");
- }
- }else{
- IRC::command ("/say $binary2");
- }
- return 1;
- }
- sub watch_binary {
- foreach $line (@_) {
- $line =~ m/\:(.*?)\!(.*?)\sPRIVMSG\s(.*?)\s\:(.*)?/;
- $m_nick = $1;
- $m_send = $2;
- $m_chan = $3;
- $m_line = $4;
- $m_line =~ s/^\s+//; # Remove trailing whitespace
- $m_line =~ s/\s+$//;
- $m_line = str_replace(" ","",$m_line);
- if(int($m_line) && length($m_line) % 8 == 0 && $m_line =~ m/^[10]*$/) {
- $s=$m_line;$l=length $s;@a=pack "B$l",$s;
- IRC::print "Binary from $m_nick: @a";
- }
- }
- }
- IRC::add_message_handler("PRIVMSG", "watch_binary");
- IRC::add_command_handler ("binary", "convert_binary");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement