Skip to content

Instantly share code, notes, and snippets.

@Oakchris1955
Created September 5, 2025 11:06
Show Gist options
  • Select an option

  • Save Oakchris1955/8a258063d2b9263d51bb960306b5827f to your computer and use it in GitHub Desktop.

Select an option

Save Oakchris1955/8a258063d2b9263d51bb960306b5827f to your computer and use it in GitHub Desktop.

Cryptography can't be stopped

Regarding recent developments around online surveillance, I decided to group some stuff that were a bit too technical for my latest blog post. While it looks like Chat Control is slowly losing steam and shifting away its focus from E2E encryption, I would still like to showcase that even if that were to change, cryptography and E2E encryption can't be stopped

Cryptography as a field has reached a state where it is possible to encrypt any piece of data both with security, meaning that you won't be able to "break" the encryption before the Heat Death of the Universe. Most cryptographically-secure algorithms that are also widely-used, like RSA and AES, are also pretty easy to implement. I am gonna showcase exactly that.

3-line RSA Perl implementation

#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)

or if you prefer it as a QR code:

image

Save this as rsa, give it execute perms (chmod 700 rsa) and use it as such

  • To encrypt with a public key:

    rsa -k=public-key -n=rsa-modulus < msg > msg.rsa

    or

    echo "msg goes here" | rsa -k=public-key -n=rsa-modulus > msg.rsa
  • To decrypt the message with the private key:

    rsa -k=private-key -n=rsa-modulus < msg.rsa > msg.out

    or

    rsa -k=private-key -n=rsa-modulus < msg.rsa # displays directly to STDOUT

Attributions:

Please note that this will encrypt the plaintext using the so-called electronic codebook/ECB block cipher mode of operation which is quite insecure and that you also need to generate the private and public key yourself, although that isn't that difficult of an operation. Yet, with just 171 characters of code we were able to implement a pretty good RSA utility given its size (please don't use this for actually cryptography by the way, use OpenSSL or OpenPGP).

"What about AES?"

Most CPUs manufactured after 2010 are essentially guaranteed to support the AES instruction set, which means you don't even have to write your own AES implementation: just use those instructions. To check (on Linux) if your computer supports the AES instruction set, run grep flags /proc/cpuinfo | grep aes. If you see the string "aes" highlighted there, your CPU supports the AES instruction set

"What about block cipher modes?"

There's a whole Wikipedia page about them which when downloaded as a PDF was less than a megabyte in size. However, I am sure that this could be condensed as far down as the RSA Perl example above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment