Aside from being a powerful and handy arbitrary precision reverse polish calculator, dc can be a nifty tool for posing as a l33t h4x0r. Sadly, not everyone has the diligence or the time to learn dc's florid syntax. Here's a small script I wrote on a boring day some time ago:



#!/usr/bin/perl

# The string to echo is of the form:
# 16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D<NUMBER>snlbxq
# where <NUMBER> is a series of hex ASCII codes (in reverse order).
# E.g.: using 6F6F66 prints "foo" as 6F == 'o', 66 == 'f'.

use strict;

die "usage: ./dcprint.pl string\n" if ($#ARGV != 0);

my @hex_values;
my $hex_code;
my $hex_number;
my $i = 0;
my $len = length($ARGV[0]);
my $char;

foreach $char (split (//, $ARGV[0])) {
        $hex_values[$len - $i++] = hexorize(ord($char));
}

foreach $hex_number (@hex_values) {
        $hex_code = $hex_code . $hex_number;
}

print "dc syntax for \"$ARGV[0]\":\n16i[q]sa[ln0=aln100\%Pln100/snlbx]sbA0D"
      . $hex_code . "snlbxq\n";

sub hexorize {
        my ($n) = @_;
        my @digit = (0 .. 9, "A" .. "F");
        my $hex = @digit[$n / 16] . @digit[$n % 16];

        return $hex;
}


It'll give you a funky-looking dc-command.

% echo "funky-looking-command" | dc

P.S. The E2 Source Code Formatter is really cool!