crypt_rsa_the_game.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/perl
  2. # Using Crypt::RSA to decrypt a message, using an explicitly given private key.
  3. use 5.014;
  4. use Crypt::RSA;
  5. my $rsa = Crypt::RSA->new;
  6. my $key = Crypt::RSA::Key->new;
  7. my ($public, $private) =
  8. $key->generate(
  9. p => "99554414790940424414351515490472769096534141749790794321708050837",
  10. q => "104593961812606247801193807142122161186583731774511103180935025763",
  11. e => 65537,
  12. )
  13. or die "error";
  14. my $cyphertext = <<'EOT';
  15. -----BEGIN COMPRESSED RSA ENCRYPTED MESSAGE-----
  16. Version: 1.99
  17. Scheme: Crypt::RSA::ES::OAEP
  18. eJwBRgC5/zEwADU0AEN5cGhlcnRleHTCFSi7dhQG4Pgmh50LyX1mGRFKbuZmdMkJW/iL5YJZHnww
  19. ECaj7l2udOqtc9L8qlsvZh24DSzKYh3A
  20. =+3dVm5h8VAg/3eTrYvDjNw==
  21. -----END COMPRESSED RSA ENCRYPTED MESSAGE-----
  22. EOT
  23. #~ my $cyphertext = $rsa->encrypt(
  24. #~ Message => $message,
  25. #~ Key => $public,
  26. #~ Armour => 1,
  27. #~ )
  28. #~ || die $rsa->errstr();
  29. #~ say $cyphertext;
  30. my $plaintext = $rsa->decrypt(
  31. Cyphertext => $cyphertext,
  32. Key => $private,
  33. Armour => 1,
  34. )
  35. || die $rsa->errstr();
  36. say $plaintext; # the game