将大整数编码/压缩为字母数字值 [英] Encoding/Compressing a large integer into alphanumeric value

查看:265
本文介绍了将大整数编码/压缩为字母数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的整数12-14位数长,我想加密/压缩这个字母数字值,以便后来可以从字母数字值恢复整数。我尝试使用62 base转换整数,并尝试将这些值映射到 a-zA-Z0-9 ,但从此生成的值为7个字符长。这个长度还够长,我想转换成约4-5个字符。



有没有一般的方法来做这个或一些方法可以完成所以恢复整数仍然是可能的?我在这里询问数学方面,但我将在PHP中进行编程,最近我开始在php中编程。



编辑:



我正在考虑分配一个屏蔽位,并以一种方式使用它来生成较少数量的Chars。我知道这个范围是不够的,这就是我专注于使用数学技巧或表达方法的原因。 62基数是一个我已经申请但尚未解决的想法。

解决方案

14位十进制数可以表达100,000,000,000,000个值10 14 )。

62个字母字母的5个字符可以表示916,132,832个值(62 5 )。



您不能将相当数量的14位数字的数字填充到5个字符的62字符串中。不可能唯一地表达每个可能的值。请参阅 http://en.wikipedia.org/wiki/Pigeonhole_principle 。即使基数为64的字符还不够(只有4,398,046,511,104个可能值)。实际上,如果你的目标是一个5个字符的短串,你需要使用一个基本的631字母表(631 5 = 100,033,806,792,151)来补偿。



即使压缩也没有帮助。这意味着两个或更多的数字将需要压缩到相同的压缩字符串(因为没有足够的可能的唯一压缩值),这在逻辑上意味着不可能将它们解压缩成两个不同的值。



简单说明:说我的字母表和目标字符串长度由一位组成。那一点可以是 0 1 。它可以表达2个独特的可能值。说我有一个压缩算法,压缩任何东西和一切,这一点。 ...我可以用两个可能的值解压缩100,000,000,000,000个独特的值吗?如果您能解决这个问题,带宽和存储问题将立即蒸发,您将成为亿万富翁。


I have a very large integer 12-14 digits long and I want to encrypt/compress this to an alphanumeric value so that the integer can be recovered later from the alphanumeric value. I tried to convert this integer using a 62 base and tried to map those values to a-zA-Z0-9, but the value generated from this is 7 characters long. This length is still long enough and I want to convert to about 4-5 characters.

Is there a general way to do this or some method in which this can be done so that recovering the integer would still be possible? I am asking the mathematical aspects here but I would be programming this in PHP and I recently started programming in php.

Edit:

I was thinking in terms of assigning a masking bit and using this in a fashion to generate less number of Chars. I am aware of the fact that the range is not enough and that is the reason I was focusing on using a mathematical trick or a way of representation. The 62 base was an Idea that I already applied but is not working out.

解决方案

14 digit decimal numbers can express 100,000,000,000,000 values (1014).
5 characters of a 62 character alphabet can express 916,132,832 values (625).

You cannot cram the equivalent number of values of a 14 digit number into a 5 character base 62 string. It's simply not possible to express each possible value uniquely. See http://en.wikipedia.org/wiki/Pigeonhole_principle. Even base 64 with 7 characters is not enough (only 4,398,046,511,104 possible values). In fact, if you target a 5 character short string you'd need to compensate by using a base 631 alphabet (6315 = 100,033,806,792,151).

Even compression doesn't help you. It would mean that two or more numbers would need to compress to the same compressed string (because there aren't enough possible unique compressed values), which logically means it's impossible to uncompress them into two different values.

To illustrate this very simply: Say my alphabet and target "string length" consists of one bit. That one bit can be 0 or 1. It can express 2 unique possible values. Say I have a compression algorithm which compresses anything and everything into this one bit. ... How could I possibly uncompress 100,000,000,000,000 unique values out of that one bit with two possible values? If you'd solve that problem, bandwidth and storage concerns would immediately evaporate and you'd be a billionaire.

这篇关于将大整数编码/压缩为字母数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆