Simple integer encryption

Is there a simple encryption algorithm for integers? That is, the function E (i, k), which takes an n-bit integer and key (of any type) and creates another, unrelated n-bit integer, which, when fed into the second function, D (E (i)) k) ( together with the key) produces the original integer?

Obviously, there are a few simple operations you can perform, but they all seem to create clearly connected outputs (for example, serial inputs lead to serial outputs). In addition, of course, there are cryptographically strong standard algorithms, but they do not give sufficiently small outputs (for example, 32-bit). I know that any 32-bit cryptography can be rude, but I'm not looking for something cryptographically strong, just something that looks random. Theoretically, this should be possible; in the end, I could just create a dictionary by randomly combining all the integers. But I was hoping for something less intense in my memory.

Edit: Thanks for the answers. Simple XOR solutions will not work because similar inputs will produce similar results.

+4
source share
9 answers

Would this Block Cipher amount be a block size = 32 bits?

Not very popular because it is easy to break. But theoretically doable. Here is one implementation in Perl: http://metacpan.org/pod/Crypt::Skip32

UPDATE: see also Save format with save

UPDATE 2: RC5 supports 32-64-128 bits for its block size

+9
source

I wrote an article some time ago on how to generate a cryptographically secure permutation from a block cipher, which sounds the way you want. It covers the use of bending to reduce the size of a block cipher and the trick for working with non-powered ranges.

+3
source

Plain:

rand = new Random(k); return (i xor rand.Next()) 

(the xor-ing point with rand.Next() , not k is that otherwise, given i and E(i,k) , you can get k by k = i xor E(i,k) )

+1
source

Aiden is an algorithm that I developed. It is compact, fast and looks very reliable. It is currently available for 32 and 64 bit integers. It is in the public domain and you can get it from github.com/msotoodeh/integer-encoder.

+1
source

You can take the n-bit hash of your key (suppose it's private) and XOR is a hash with the original integer for encryption and with the decrypted encrypted integer.

Probably not cryptographically enough, but depending on your requirements may be enough.

0
source

If you just want to look random and don't care about security, how about just replacing bits around. You can just flip the bit string, so the high bit becomes the lowest, second, second, lowest, etc., Or you can do some other random permutation (for example, from 1 to 4, from 2 to 7 3 to 1 etc.

0
source

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

If you have several elements for encryption and you are ready to deal with key data, which is as long as the data you want to encrypt, then a one-time pad is very simple (just an XOR operation) and mathematically indestructible.

The disadvantage is that the problem of maintaining the security of the key is about the same as the problem of maintaining the security of your data.

It also has the drawback (which starts on time and again when someone decides to try to use it) that if you take any shortcuts - for example, using a non-random key or a regular key with a limited length and processing it - that it becomes the weakest cipher in existence. Well, maybe ROT13 is weaker.

But in all seriousness, if you are encrypting an integer, what are you going to do with the key no matter which cipher you decide? Maintaining the secret of a key will be a problem as big (or greater) than keeping a whole secret. And if you encrypt a bunch of integers, just use the standard, expert-verified cipher that you will find in many cryptographic libraries.

RC4 will produce as little information as possible, as it is a stream cipher.

0
source

How about XORing with a simple or two? When you try to analyze this happens when you switch bits around. Try something along the lines of XORing with a simple and self after bit offset.

0
source

XOR is with / dev / random

0
source

Source: https://habr.com/ru/post/1308831/


All Articles