Skip to content

Instantly share code, notes, and snippets.

@peczenyj
Created June 7, 2013 13:26
Show Gist options
  • Select an option

  • Save peczenyj/5729243 to your computer and use it in GitHub Desktop.

Select an option

Save peczenyj/5729243 to your computer and use it in GitHub Desktop.
simple lelek generator
use strict;
use warnings;
package LekLek;
use Convert::BaseN;
use Const::Fast;
use Moo;
const my @leks => qw(lek leK lEk Lek lEK LeK LEk LEK);
const my %octals => map { $leks[$_] => $_ } 0..7;
has base8 => (is => 'ro', default => sub {
Convert::BaseN->new(base => 8)
});
sub encode {
my ($self, $msg) = @_;
join q( ), map { $leks[$_] } grep /[0-8]/, split q(), $self->base8->encode($msg);
}
sub decode {
my ($self, $msg) = @_;
$self->base8->decode(join q(), map { $octals{$_} } split(qr/\s+/, $msg));
}
package main;
use feature 'say';
my $lek = LekLek->new;
my $encoded = $lek->encode("girando girando");
say "encoded : $encoded";
say "original: " . $lek->decode($encoded);
encoded : Lek leK LEk LEk lEK LeK LEk lEk Lek lek lEk LEk LEK leK lEK lEK Lek Lek LEk lEk lek leK lEK LEK Lek lEk lEk LEK leK leK lEK leK Lek Lek lEK LEk lEk leK LeK LEK
original: girando girando
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment