Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Enigma machine - WW2

Anakthewolf May 11th, 2014 290 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use warnings;
  5. use feature 'say';
  6. use Switch;
  7.  
  8. use Crypt::Enigma;
  9.  
  10. # i 5 rotori di cui se ne sceglieranno 3 - definiti in enigma.pm
  11. #our (@ROTOR0) = qw (e k m f l g d q v z n t o w y h x u s p a i b r c j);
  12. #our (@ROTOR1) = qw (a j d k s i r u x b l h w t m c q g z n p y f v o e);
  13. #our (@ROTOR2) = qw (b d f h j l c p r t x v z n y e i w g a k m u s q o);
  14. #our (@ROTOR3) = qw (e s o v p z j a y q u i r h x l n f t g k d c m w b);
  15. #our (@ROTOR4) = qw (v z b r g i t y u p s d n h l x a w m j q o f e c k);
  16.  
  17. # istanzia oggetto macchina Enigma
  18. my $enigma = Crypt::Enigma->new();
  19.  
  20. # Selezione dei rotori - cablaggio interno dello scambiatore - posizione iniziale rotore
  21. $enigma->setup('312', 'ABC', 'ERZ');
  22.  
  23. # Scambio a to b, b to a - plugboard di Enigma, come fosse un ulteriore rotore
  24. $enigma->stekker('a', 'b');
  25.  
  26. my $plainText;
  27. switch (defined($ARGV[0])) {
  28.         case '' {
  29.                 $plainText='workshop at unina mmxiv'
  30.         }
  31.         else {
  32.                 $plainText=lc($ARGV[0])
  33.         }
  34. }
  35.  
  36. say '--> Testo in chiaro: '.$plainText;
  37. $plainText =~ s/[^\w]|[^\D]//g;
  38.  
  39. my $encryptedText;
  40. foreach my $character (split (//,$plainText)) {
  41.         $encryptedText.=$enigma->input($character)
  42. }
  43.  
  44. say '--> Testo criptato: '.$encryptedText;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top