It probably goes without saying but you wouldn’t really want to use keys generated with this, since what RNG is used for .pick() depends on what implementation, VM and platform you’re using. Rakudo on MoarVM uses arc4random() on the BSDs and rand() everywhere else.

(You shouldn’t use a random perl script, that’s just trying to show off an implementation, to encrypt sensitive data? Say it ain’t so!)

Great blog post! Lots of neat Perl 6isms. RSA-wise, it might be faster to first pick your e (real-world implementations choose from a fixed list of so-called “public exponents” [read: 3 or 65537] that are known to make modular exponentiation faster) and then to repeatedly search for primes p, q of the desired size such that p mod e != 1 and q mod e != 1. You can also make your prime search slightly faster by generating only a list of odd numbers; I imagine there’s some sort of cool Perl 6 syntax for doing skips in list sequences.

It probably goes without saying but you wouldn’t really want to use keys generated with this, since what RNG is used for .pick() depends on what implementation, VM and platform you’re using. Rakudo on MoarVM uses arc4random() on the BSDs and rand() everywhere else.

(You shouldn’t use a random perl script, that’s just trying to show off an implementation, to encrypt sensitive data? Say it ain’t so!)

Also never use RSA without proper padding!

Great blog post! Lots of neat Perl 6isms. RSA-wise, it might be faster to first pick your

`e`

(real-world implementations choose from a fixed list of so-called “public exponents” [read: 3 or 65537] that are known to make modular exponentiation faster) and then to repeatedly search for primes`p, q`

of the desired size such that`p mod e != 1`

and`q mod e != 1`

. You can also make your prime search slightly faster by generating only a list of odd numbers; I imagine there’s some sort of cool Perl 6 syntax for doing skips in list sequences.Good point – I actually addressed the randomness issue in the version of this code that I put on modules.perl6.org.