Created
June 7, 2013 13:26
-
-
Save peczenyj/5729243 to your computer and use it in GitHub Desktop.
simple lelek generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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