summaryrefslogtreecommitdiff
path: root/t/full-enigma.t
diff options
context:
space:
mode:
Diffstat (limited to 't/full-enigma.t')
-rw-r--r--t/full-enigma.t69
1 files changed, 69 insertions, 0 deletions
diff --git a/t/full-enigma.t b/t/full-enigma.t
new file mode 100644
index 0000000..0015b46
--- /dev/null
+++ b/t/full-enigma.t
@@ -0,0 +1,69 @@
+#!perl
+use DAKKAR::p 'test';
+
+use Enigmatic::Machine;
+
+sub real_machine {
+ return Enigmatic::Machine->new({
+ reflector => 'B_thin',
+ rotors => [ 'I', 'IV', 'II', 'Beta' ],
+ plugboard => 'AT BL DF GJ HM NW OP QY RZ VX',
+ ring_settings => [ 'V', 'A', 'A', 'A' ],
+ rotor_positions => [ 'A', 'N', 'J', 'V' ],
+ });
+}
+
+my $plaintext = <<'EOPLAIN';
+VONV ONJL OOKS JHFF TTTE
+INSE INSD REIZ WOYY QNNS
+NEUN INHA LTXX BEIA NGRI
+FFUN TERW ASSE RGED RUEC
+KTYW ABOS XLET ZTER GEGN
+ERST ANDN ULAC HTDR EINU
+LUHR MARQ UANT ONJO TANE
+UNAC HTSE YHSD REIY ZWOZ
+WONU LGRA DYAC HTSM YSTO
+SSEN ACHX EKNS VIER MBFA
+ELLT YNNN NNNO OOVI ERYS
+ICHT EINS NULL
+EOPLAIN
+$plaintext =~ s{\s+}{}g;
+
+my $ciphertext = <<'EOCIPHER';
+NCZW VUSX PNYM INHZ XMQX
+SFWX WLKJ AHSH NMCO CCAK
+UQPM KCSM HKSE INJU SBLK
+IOSX CKUB HMLL XCSJ USRR
+DVKO HULX WCCB GVLI YXEO
+AHXR HKKF VDRE WEZL XOBA
+FGYU JQUK GRTV UKAM EURB
+VEKS UHHV OYHA BCJW MAKL
+FKLM YFVN RIZR VVRT KOFD
+ANJM OLBG FFLE OPRG TFLV
+RHOW OPBE KVWM UQFM PWPA
+RMFH AGKX IIBG
+EOCIPHER
+$ciphertext =~ s{\s+}{}g;
+
+note "encrypt real";
+
+my $check = real_machine->map_string($plaintext);
+p $check;
+is($check,$ciphertext,
+ 'ok crypt');
+
+note "round-trip check";
+
+$check = real_machine->map_string($check);
+p $check;
+is($check,$plaintext,
+ 'round tripped');
+
+note "decrypt real";
+
+$check = real_machine->map_string($ciphertext);
+p $check;
+is($check,$plaintext,
+ 'ok plain');
+
+