4
\$\begingroup\$

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!

Input:

AES Encryption!
averygoodsecretpasswordthatsgood

Output:

VBWQy7umRdabP1xs2y1Oqg==

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

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Why convert to Base64? Feels like an unneeded step in the challenge. \$\endgroup\$
    – ATaco
    Feb 28 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
    Feb 28 at 22:28
  • \$\begingroup\$ Ah, Canonical to the challenge makes sense. Wouldn't a Byte-array work instead though? \$\endgroup\$
    – ATaco
    Feb 28 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\$ Mar 1 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\$ Mar 1 at 15:55

1 Answer 1

5
\$\begingroup\$

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.

s=>k=>[...(c=require('crypto').createCipheriv("aes-256-ecb",k,"")).update(s),...c.final()]

Try it online!

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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