<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# version 0.5
# strings with ascii characters not exceeding 0x7f can be shortened by compression (use of free bits)
# the following was used as a guiding example: http://www.dreamfabric.com/sms/hello.html 
print "Enter 1 for string (septet) to hex octet\n";
print "Enter 2 for hex octet to string (septet)\n";
$selection = &lt;STDIN&gt;;
chop $selection;
if ( $selection == "1" ) {
   print "Enter the text string\n";
   $a = &lt;STDIN&gt;;
   chop $a;
   print "line entered is: $a\n";
   @out = unpack("C*",$a); # Unpack to binary
   $length_of_array_septet = scalar(@out);
   $length_of_array_octet = $length_of_array_septet;
   $index = 0;
   while ($index &lt; $length_of_array_octet) {
      for ($byte=0,$shift=7;$byte &lt; 7 &amp;&amp; (($byte + $index) &lt; $length_of_array_octet) ; $byte++,$shift--) {
          $counter = $byte + $index;
          $out[$counter]=$out[$counter] &gt;&gt; $byte | ((0xff &gt;&gt; $shift) &amp; $out[$counter + 1]) &lt;&lt; $shift;
      }
      for ($i=$index + 7;$i &lt; $length_of_array_octet;$i++) {
         $out[$i] = $out[$i + 1];
      }
      $index = $index + 7;
      $length_of_array_octet = $length_of_array_octet - 1;
   }
   for ($index=0;$index &lt;= $length_of_array_octet;$index++) {
      printf("%x ",$out[$index]);
   }
}
else {
   print "Enter the hex string (space separated)\n";
   $a = &lt;STDIN&gt;;
   chop $a;
   @out = unpack("C*",$a); # Unpack to binary
   $length_of_array_octet = scalar(@out);
   $counter = 0;
   $length_concatenation = $length_of_array_octet;
   for ($i=0;$i &lt;= $length_of_array_octet;$i++) {
      if ($out[($i + 1)] == 32) {
         if (($out[$i] &gt;= 48) &amp;&amp; ($out[$i] &lt;= 57)) { $out[$i] = $out[$i] - 48};
         if (($out[$i] &gt;= 97) &amp;&amp; ($out[$i] &lt;= 102)) { $out[$i] = $out[$i] - 87};
         for ($j = $i ;$j &lt; $length_concatenation;$j++) {
            $out[($j + 1)] = $out[($j + 2)];
         }
         $length_concatenation = $length_concatenation - 1;
      }
      else {
         if (($out[($i + 1)] &gt;= 48) &amp;&amp; ($out[($i + 1)] &lt;= 57)) { $out[($i + 1)] = $out[($i + 1)] - 48};
         if (($out[($i + 1)] &gt;= 97) &amp;&amp; ($out[($i + 1)] &lt;= 102)) { $out[($i + 1)] = $out[($i + 1)] - 87};
         if (($out[$i] &gt;= 48) &amp;&amp; ($out[$i] &lt;= 57)) { $out[$i] = ($out[$i] - 48) * 16};
         if (($out[$i] &gt;= 97) &amp;&amp; ($out[$i] &lt;= 102)) { $out[$i] = ($out[$i] - 87) * 16};
         $out[$i] = $out[($i + 1)] + $out[$i];
         for ($j = $i ;$j &lt; $length_concatenation;$j++) {
            $out[($j + 1)] = $out[($j + 2)];
         }
         $length_concatenation = $length_concatenation - 1;
         for ($j = $i ;$j &lt; $length_concatenation;$j++) {
            $out[($j + 1)] = $out[($j + 2)];
         }
         $length_concatenation = $length_concatenation - 1;
      } 
   }
   print "\n";
   print "Text is:\n";
   $index = 0;
   $index2 = 0;
   while (($length_of_array_octet - $index) &gt; 8) {
      for ($i = 7, $j = 1;$i &gt; 0 ; $i--,$j++) {
         $counter = $i + $index;
         $counter2 = $i + $index2;
         $out2[$counter2] = ($out[$counter] &amp; (0x7f &gt;&gt; $i)) &lt;&lt; $i | ($out[($counter - 1)] &gt;&gt; $j);
      }
      $out2[$index2] = $out[$index] &amp; 0x7f;
      $index = $index + 7;
      $index2 = $index2 + 8;
   }
   for ($index=0;$index &lt;= $length_of_array_octet;$index++) {
      printf("%c",$out2[$index]);
   }   
}

</pre></body></html>