Skip to content

Instantly share code, notes, and snippets.

@TinoDidriksen
Last active April 2, 2025 13:29
Show Gist options
  • Select an option

  • Save TinoDidriksen/6f6606a90dd4e6d94b8c34f8b80b2fcd to your computer and use it in GitHub Desktop.

Select an option

Save TinoDidriksen/6f6606a90dd4e6d94b8c34f8b80b2fcd to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Digest::SHA qw(sha256_base64);
sub hash_base62 {
my ($s, $n) = @_;
utf8::encode($s);
$s = sha256_base64($s);
$s =~ s@=+@@g;
$s =~ s@[+]@x@g;
$s =~ s@/@X@g;
return substr($s, 0, $n);
}
my $i = 0;
while (my $line = <STDIN>) {
++$i;
my $h = hash_base62($line . $i, 14);
print "$h\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment