# Lightweight length preserving encryption

I'm in need of an encryption algorithm that can be easily implemented in c, doesn't drastically increase the size of the encrypted data (the data to be encrypted will be approximately 200 bytes and the size can't increase by more than 15%) It is also important for the algorithm to be quite lightweight as it's going to be running on minimal hardware. I initially tried RSA with two 4-digit prime decimal numbers for the key generation and it worked but decoding took more than 40 seconds on my home computer so it would be completely unviable on a microcontroller. I then looked into SPECK and SIMON but the single example i was able to find didn't produce the correct results. Also the fact that SPECK and SIMON are block ciphers introduces more issues. Is there another cipher that fits my requirements? Thanks in advance

• "RSA with two 4-digit prime", This is an alarming sign that you have no clue of what you're doing! And even a 2048-bit modulus won't take nearly 40 seconds to decrypt! The best case scenario with this is that tell us what kind of application you're developing, and we may be able to suggest an existing product that cover your need. Apr 10 at 1:21
• this question doesn't really make sense. are you looking for symmetric or asymmetric encryption? Apr 10 at 1:46
• @DannyNiu I know RSA with that kind of numbers is terribly insecure. My main priority is it being lightweight (encryption is just for show on this project to be honest) so before i found out about dedicated lightweight algorithms (cryptography isn't exactly my thing as you can probably tell) I tried that. If however there's a way to have some kind of security, I much prefer that. Now as for why RSA decryption takes so long, I'm probably doing something terribly wrong but as RSA is probably not the way to go, I didn't troubleshoot it further. Apr 10 at 6:13
• If it has to be implemented from bare C (no library), and only confidentiality (not integrity) is thought, I would suggest a block cipher (like TEA which is particularly simple to code, SIMON, SPECK) in CTR, CFB or OFB mode.
– fgrieu
Apr 10 at 7:04