# Encrypting big numbers into small ones?

I'm new to cryptography and I am trying to figure out an equation that convert any big number to a smaller one and another one that reverse the operation to get the same big number again!

The problem here is every equation I use works fine with some numbers and others no.

I want one that works with all like:

Encrypted = Data - key
Data = Encrypted + key


But of course I want it to be more difficult :)

Can any one help me with that ?

• Compressed binary numbers but with my own way,the length range is more than 500 numbers maybe :D and yes I'm thinking about encryption not compression – D4Vinci Jun 30 '16 at 5:45
• "more than 500 numbers" - you mean digits? – tum_ Jun 30 '16 at 6:36
• Yes I mean digits – D4Vinci Jun 30 '16 at 12:52
• My immediate thought is to divide the huge number by a large enough power of 10, so that it is now small. – Garrison Pendergrass Oct 19 '16 at 17:51

What you're asking for is impossible by a very simple argument. If you're mapping a large number of things to a smaller number of things, more than one of the things from the bigger group will get mapped into the same thing in the smaller group. This is the pigeonhole principle.

When you get your "small number" there will be several different large numbers that could have been mapped to it. You won't be able to recover the original large number with any certainty.

• Well, not necessarily - he(she) gave a good example of how smth like this can be achieved ;) But this has nothing to do with cryptography, of course. @VH4Ck - when dealing with crypto, rule #1 is "Don't invent your own ciphers", inventing a good one is (almost) impossible for a newbie, so why wasting your time... – tum_ Jun 30 '16 at 5:18
• Thanks for your answer @A.Toumantsev I know you are right but the problem is..I can't stop my self from doing cuz I love crypto very much from the first article I read about crypto,I edited a lot of famous ciphers and made it stronger(like anyone can)then I decided to do one with myself and made many ones from the last month and python scripts for it but it always fail.! -thank u 4 trying to help me,I appreciate it – D4Vinci Jun 30 '16 at 5:38
• OK, I will rephrase - no one can stop you from doing whatever you want to do. But questions like this, not actually related to cryptography, will be downvoted and eventually closed. Other people do not want to waste their time on things like that. – tum_ Jun 30 '16 at 6:34
• Who can help me do it will help me.That's what I know and I won't despair.! – D4Vinci Jun 30 '16 at 12:50

Assuming the set of large numbers is small (otherwise you cannot represent them all as small numbers), what you are looking for can be broken into two steps:

1. Transform the large numbers into small ones.
2. Encrypt them.

The first problem is not really cryptographic. In the simplest case it can be simply subtraction. If your set of numbers is sparse it can be accomplished with a (minimal) perfect hash function - which I must warn you are not cryptographic hash functions. Such functions map a predefined set of values into another, which in this case you want to be small integers.

Once you have transformed the values, the choice of encryption depends on your requirements. Simplest and most secure would be using a normal authenticated encryption algorithm on them, but then you would again have large values. Some kind of format-preserving encryption may be required.