I've looked and could not find a post for this, if there is one, I'll remove it quick! Related and also related

The goal is (hopefully) clear: create the shortest code (in bytes) that implements the AES256 ECB cipher mode. Either convert the result to Base64 or output a array of bytes. The input contains two parts. The first part is the stuff to encrypt, and the second part (separated by newlines) is the secret key. You do not need to decrypt it!

Test cases!


AES Encryption!



You may output as an array of bytes too, if you wish.

  • 1
    \$\begingroup\$ Why convert to Base64? Feels like an unneeded step in the challenge. \$\endgroup\$
    – ATaco
    Commented Feb 28, 2023 at 22:25
  • \$\begingroup\$ Well, it could contain some unicode characters that cannot be seen, and that's pretty much what every program to calculate AES (golfed or not) does. \$\endgroup\$
    – Infigon
    Commented Feb 28, 2023 at 22:28
  • \$\begingroup\$ Ah, Canonical to the challenge makes sense. Wouldn't a Byte-array work instead though? \$\endgroup\$
    – ATaco
    Commented Feb 28, 2023 at 22:37
  • 2
    \$\begingroup\$ Please could you put a step-by-step explanation of what is involved in implementing the AES256-ECB mode encryption into the text of the challenge? Or/and a non-golfed example. \$\endgroup\$ Commented Mar 1, 2023 at 13:22
  • 1
    \$\begingroup\$ You should clarify that you use PKCS#7, or, and I think this is a better option, guarantee that the block is 16 bytes and don't have any padding. \$\endgroup\$ Commented Mar 1, 2023 at 15:55

1 Answer 1


JavaScript (Node.js), 90 bytes

Disclaimer: even with clean ungolfed code, don't use ECB mode for anything serious unless you're 100% certain its weaknesses are acceptable for your use case.

Expects (string)(key) and returns an array of bytes.


Try it online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.