Simple integer encryption

后端 未结 9 1455
南方客
南方客 2020-12-03 06:24

Is there a simple algorithm to encrypt integers? That is, a function E(i,k) that accepts an n-bit integer and a key (of any type) and produces another, unrelated n-bit integ

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 06:46

    How many integers do you want to encrypt? How much key data do you want to have to deal with?

    If you have few items to encrypt, and you're willing to deal with key data that's just as long as the data you want to encrypt, then the one-time-pad is super simple (just an XOR operation) and mathematically unbreakable.

    The drawback is that the problem of keeping the key secret is about as large as the problem of keeping your data secret.

    It also has the flaw (that is run into time and again whenever someone decides to try to use it) that if you take any shortcuts - like using a non-random key or the common one of using a limited length key and recycling it - that it becomes about the weakest cipher in existence. Well, maybe ROT13 is weaker.

    But in all seriousness, if you're encrypting an integer, what are you going to do with the key no matter which cipher you decide on? Keeping the key secret will be a problem about as big (or bigger) than keeping the integer secret. And if you're encrypting a bunch of integers, just use a standard, peer reviewed cipher like you'll find in many crypto libraries.

    RC4 will produce as little output as you want, since it's a stream cipher.

提交回复
热议问题