summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Enigmatic/RotorBox.pm34
-rw-r--r--t/rotors.t26
2 files changed, 60 insertions, 0 deletions
diff --git a/lib/Enigmatic/RotorBox.pm b/lib/Enigmatic/RotorBox.pm
new file mode 100644
index 0000000..08a6b22
--- /dev/null
+++ b/lib/Enigmatic/RotorBox.pm
@@ -0,0 +1,34 @@
+package Enigmatic::RotorBox;
+use DAKKAR::p 'class';
+use Enigmatic::Rotor;
+use MooseX::Types::Structured qw(Map);
+use MooseX::Types::Moose qw(Str);
+use Moose::Util::TypeConstraints;
+
+has rotorset => (
+ is => 'ro',
+ isa => Map[Str,class_type('Enigmatic::Rotor')],
+ lazy_build => 1,
+ traits => ['Hash'],
+ handles => {
+ get => 'get',
+ },
+);
+
+sub _build_rotorset {
+ my %rotors = (
+ I => 'EKMFLGDQVZNTOWYHXUSPAIBRCJ',
+ II => 'AJDKSIRUXBLHWTMCQGZNPYFVOE',
+ III => 'BDFHJLCPRTXVZNYEIWGAKMUSQO',
+ IV => 'ESOVPZJAYQUIRHXLNFTGKDCMWB',
+ V => 'VZBRGITYUPSDNHLXAWMJQOFECK',
+ VI => 'JPGVOUMFYQBENHZRDKASXLICTW',
+ VII => 'NZJHGRCXMYSWBOUFAIVLPEKQDT',
+ VIII => 'FKQHTLXOCBJSPDZRAMEWNIUYGV',
+ Beta => 'LEYJVCNIXWPBQMDRTAKZGFUHOS',
+ Gamma => 'FSOKANUERHMBTIYCWLQPZXVGJD',
+ );
+
+ $_ = Enigmatic::Rotor->new($_) for values %rotors;
+ return \%rotors;
+}
diff --git a/t/rotors.t b/t/rotors.t
index 509d88d..fb53fe4 100644
--- a/t/rotors.t
+++ b/t/rotors.t
@@ -3,6 +3,7 @@ use DAKKAR::p 'test';
use List::Util 'shuffle';
use Enigmatic::Rotor;
+use Enigmatic::RotorBox;
sub test_the_rotor {
my ($r,$out,$name) = @_;
@@ -56,4 +57,29 @@ subtest 'constraints' => sub {
}
};
+subtest 'rotor box' => sub {
+ my %rotors = (
+ I => 'EKMFLGDQVZNTOWYHXUSPAIBRCJ',
+ II => 'AJDKSIRUXBLHWTMCQGZNPYFVOE',
+ III => 'BDFHJLCPRTXVZNYEIWGAKMUSQO',
+ IV => 'ESOVPZJAYQUIRHXLNFTGKDCMWB',
+ V => 'VZBRGITYUPSDNHLXAWMJQOFECK',
+ VI => 'JPGVOUMFYQBENHZRDKASXLICTW',
+ VII => 'NZJHGRCXMYSWBOUFAIVLPEKQDT',
+ VIII => 'FKQHTLXOCBJSPDZRAMEWNIUYGV',
+ Beta => 'LEYJVCNIXWPBQMDRTAKZGFUHOS',
+ Gamma => 'FSOKANUERHMBTIYCWLQPZXVGJD',
+ );
+
+ my $box = Enigmatic::RotorBox->new();
+
+ %rotors->each(sub {
+ my ($rotor,$wiring) = @_;
+ my $r = $box->get($rotor);
+ my $out = $wiring->split(qr//);
+ test_the_rotor($r,$out,
+ "rotor $rotor from box");
+ });
+};
+
done_testing();