Score:0

Any number-to-number cipher?

us flag

I am curious (not technically informed) if the number-to-number cipher is common/useful in cryptography.

Imagine, we want to cipher integer y to integer x. Using a formula like

x = 2 * y - 1

one can easily decipher by having a few examples of matching x-y. The first problem is that the sequence of y integers is identical to that of x.

Is there a way to cipher integers while the output is a similar integer (not insanely larger; e.g., changing a 6-digit number to a 6-8-digit number)?

bk2204 avatar
fr flag
Are you asking about a design that provides a consistent mapping between input and output numbers (which is insecure), or are you asking about a secure design?
us flag
@bk2204 it is a consistent mapping, as someone with the key can directly get `y` out of `x`. Surely, it is not as secure as one-way hashing; but the complexity of the key makes it harder to decipher.
fgrieu avatar
ng flag
You seem to be asking for Format-Preserving Encryption, a special form of block cipher which can accommodate plaintext and ciphertext in a prescribed format, e.g. 7-digits. You do _not_ seem to be looking for a stream cipher, thus I changed the tag. If FPE does the job, please close the question unless you want more info on FPE (perhaps an intro or simple example algorithm), in which case specify your constraints: doable with computer, handheld calculator, pen and paper... fixed or variable size for plaintext and ciphertext, leading zero significant or not...
us flag
@fgrieu thanks for the clarification. You're right, it probably does not fall within the scope of stream cipher, but it is not a typical block cipher either. The mode is electronic codebook, but as I understand, block cipher transform each character into a new one. My question is to treat the input as a number (not a set of digits). We do not need to keep the size of output equal to the input. I just stressed that the output should not be insanely large. For example, we use the formula `x = a * y^3 + b * y^2 + c * y + d`. It will be really hard to decipher the output, but will be too large.
fgrieu avatar
ng flag
If something that can be an integer $[0..999999]$ (up to 6 decimal digits) for the plaintext is OK, and you allow the output to be sizably larger than the input, e.g. an integer in say $[0..2^{33}-1]$ (that fits 10 decimal digits), then you can use any standard cipher, stream or not (e.g. the common AES-CTR) with a mere conversion from decimal to binary of the plaintext (20-bits), and binary to decimal of the IV+ciphertext (13+20 bit). You don't need full-blown FPE, Sure the IV is small; and you don't have authenticated encryption, but that's not asked. I can detail in an answer if necessary.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.