# Roboticus' second attempt my $robo_2 = sub { my @orig = unpack "S*", shift; my $bits=0; my $buf=0; my @bytes; while (@orig) { $buf |= (shift @orig)<<$bits; $bits += 16; while ($bits>6) { push @bytes, $buf & 0x3f; $buf>>=6; $bits-=6; } } push @bytes, $buf if $bits; return (@bytes); }; #### roboticus@Boink:~ $ cat 876421.pl #!/usr/bin/perl use strict; use warnings; my $orig = "Now is the time for all "; my $enc = pack "u", $orig; print "$enc\n"; my $dec = unpack "u", $enc; print "$dec\n"; my (undef, @bytes) = map { 0x3f & ord($_) } split //, $enc; printf "%02x ", $_ for @bytes; roboticus@Boink:~ $ perl 876421.pl 83F]W(&ES('1H92!T:6UE(&9O## #include unsigned char inbuf[]="Now is the time for all "; unsigned char outbuf[50]; void hexdump(unsigned char *p, int n) { for (int i=0; i 6) { *dst++ = buf & 0x3f; buf >>= 6; bits -= 6; } } hexdump(outbuf, dst-outbuf); }