Memfrob
November 10, 2020
Memfrob is a light encryption algorithm that works by xor
-ing 4210 = 001010102 with each input byte to create encrypted output; decryption is symmetric with encryption. Memfrob is roughly equivalent to ROT13 in cryptographic security.
Your task is to implement memfrob. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
A quick solution using standard Scheme:
In Python:
Input argument must be a bytes-like object.
Here are a few solutions in C. The first is a plain vanilla implementation, followed by an implementation that uses
memfrob
from the GNU C library, and then an implementation that uses AVX2 intrinsics (the other solutions—compiled with optimizations—are still faster in my tests on a large file).Example usage: