Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #!/usr/bin/perl
  2. IRC::print "Loading llrcombs's Binary/ASCII converter script";
  3.  
  4. #Replace a string without using RegExp.
  5. sub str_replace
  6. {
  7. my $search = shift;
  8. my $replace = shift;
  9. my $subject = shift;
  10. if (! defined $subject) { return -1; }
  11. my $count = shift;
  12. if (! defined $count) { $count = -1; }
  13.  
  14. my ($i,$pos) = (0,0);
  15. while ( (my $idx = index( $subject, $search, $pos )) != -1 )
  16. {
  17. substr( $subject, $idx, length($search) ) = $replace;
  18. $pos=$idx+length($replace);
  19. if ($count>0 && ++$i>=$count) { last; }
  20. }
  21.  
  22. return $subject;
  23. }
  24.  
  25. sub convert_binary
  26. {
  27. my $query = shift;
  28. $l=(length $query)*8;@a=unpack "B$l",$query;
  29.  
  30. $binary = "";
  31.  
  32. foreach $line (@a){
  33. $binary = $binary.$line;
  34. }
  35.  
  36. $binary = "$binary";
  37.  
  38. $i = 0;
  39.  
  40. $binary2 = "";
  41.  
  42. foreach $digit (split(undef,$binary)){
  43. $i++;
  44. $binary2 = $binary2.$digit;
  45. if($i == 8){
  46. $binary2 = $binary2." ";
  47. $i = 0;
  48. }
  49. }
  50. IRC::print ("Sent binary: $query");
  51. if(length($binary2)>422){
  52. while(length($binary2)){
  53. $binary_432 = substr($binary2,0,422);
  54. $binary2 = substr($binary2,423);
  55. IRC::command ("/say $binary_432");
  56. }
  57. }else{
  58. IRC::command ("/say $binary2");
  59. }
  60.  
  61. return 1;
  62. }
  63.  
  64. sub watch_binary {
  65. foreach $line (@_) {
  66. $line =~ m/\:(.*?)\!(.*?)\sPRIVMSG\s(.*?)\s\:(.*)?/;
  67.  
  68. $m_nick = $1;
  69. $m_send = $2;
  70. $m_chan = $3;
  71. $m_line = $4;
  72.  
  73. $m_line =~ s/^\s+//; # Remove trailing whitespace
  74. $m_line =~ s/\s+$//;
  75.  
  76. $m_line = str_replace(" ","",$m_line);
  77. if(int($m_line) && length($m_line) % 8 == 0 && $m_line =~ m/^[10]*$/) {
  78. $s=$m_line;$l=length $s;@a=pack "B$l",$s;
  79. IRC::print "Binary from $m_nick: @a";
  80. }
  81. }
  82. }
  83.  
  84.  
  85.  
  86. IRC::add_message_handler("PRIVMSG", "watch_binary");
  87.  
  88. IRC::add_command_handler ("binary", "convert_binary");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement