holyhippie: (Default)
[personal profile] holyhippie
Here's a snippet of code inspired by this page, on an minor technical feature of the email server I work with on a regular basis.

#!/usr/bin/perl

sub hashdir($) {
  my ($orig) = @_;
  my $hashval = 0;

  foreach my $char (split(//,$orig)) {
    use integer;
    $hashval = $hashval*31 + ord($char);
  }
  $char1 = $hashval & 0xf;
  $hashval = $hashval >> 4;
  $char2 = $hashval & 0x7;
  $hashval = $hashval >> 3;
  $char3 = $hashval & 0xf;
  $hashval = $hashval >> 4; 
  $char4 = $hashval & 0x7;
  return sprintf ("%x%x/%x%x/", $char1, $char2, $char3, $char4);
}

print hashdir($ARGV[0]), "\n";
Page generated Jul. 26th, 2017 08:33 pm
Powered by Dreamwidth Studios