0

I have a 6 digit decimal integer whose range is 0 to 999999. I have a 128 bit key. How can I encrypt the number and have a result that is smaller than 8 bytes? I have tried a few samples from MSDN and I end up with a 16 or 8 byte result. Is getting a result with more like 12 digits or fewer possible?

JohnWrensby
  • 2,652
  • 1
  • 18
  • 18

2 Answers2

1

Convert the decimal into a byte array and xor it with the key. This is essentially a One-time pad.

Other than that, basically all stream ciphers can do what you want. For example AES in CTR mode or RC4.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • One-time pad is brilliant and fascinating. – JohnWrensby Mar 09 '15 at 20:58
  • You really have to keep in mind the *one-time* part of OTP. Although this is not in the name, stream ciphers without a nonce (which blows up the ciphertext and may break your requirement of it being smaller than 8 bytes) have the same problem that the key can be used only once. – Artjom B. Mar 09 '15 at 21:08
0

use rc4 its output is the same size as its input

pm100
  • 48,078
  • 23
  • 82
  • 145