#!/usr/bin/perl use strict; use warnings; # Base 24 question from https://twitter.com/pwnallthethings/status/1343590455511023621 my @digits = qw/B C D F G H J K M P Q R T V W X Y 2 3 4 6 7 8 9/; my %digit_value; my $string = 'FCKGW-RHQQ2-YXRKT-8TG6W-2B7Q8'; # Convert a base 24 number to decimal. This is a group of five # numbers, like a Windows key. { my $v = 0; foreach my $d ( @digits ) { $digit_value{ $d } = $v++; } my @units = split ( /-/, $string ); foreach my $u ( @units ) { my $value = decode ( $u ); print "$u -> $value\n"; } } sub decode { my ( $str ) = @_; my $val = 0; my @chars = split ( //, $str ); foreach my $c ( @chars ) { $val *= 24; $val += $digit_value{ $c }; } return $val; }