数值,可逆,伪随机数生成器,用于非常大的数 [英] Numeric, reversible, pseudorandom number generator, for very large numbers

查看:76
本文介绍了数值,可逆,伪随机数生成器,用于非常大的数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道适合上述所有条件的算法吗?我需要指定一个种子编号,以及一个我希望输出数字落入的范围(这也是输入数字所在的范围).此功能还需要有一个与之相反的操作.

Does anyone know of an algorithm that fits all of the above criteria? I need to specify a seed number, and a range that I want the output numbers to fall under (which will also be the range that the input numbers are in). This function also needs to have a counterpart that reverses the operation.

例如:

我将种子5和范围5-35传递给了我,然后我得到了数字27.然后我可以将其传递给一个函数,该函数使用相同的范围来反转操作,这将使我得到5.

I pass the seed 5, and the range 5-35, then I receive the number 27. I can then pass this into a function that reverses the operation, using the same range, that will give me the number 5 back.

我无法存储原始数字,也无法遍历输入数字的列表.这不一定是加密强度,而且必须尽可能快.

I cannot store the original numbers, nor can I iterate through a list of the input numbers. This does not have to be encryption strength, and it has to be as fast as possible.

我认为适合这种描述的唯一一件事就是加密算法.甚至正确方向上的一点也很棒.

The only thing I can think of that sort of fits this description is an encryption algorithm. Even a point in the right direction would be awesome.

编辑

我正在尝试找到一种方法来表示一组太大的随机(看起来)数字(无法存储在内存中)(可能是3e12个数字),然后测试该集合中是否出现了一定范围的数字.

I am trying to find a way to represent a set of random (looking) numbers that is too large to hold in memory (possibly 3e12 numbers), and then test if certain ranges of numbers show up in that set.

例如.如果我有一个函数可以给我随机集(4,22,7,343,67,38,2),我想可以说一下,请给我这个随机集中介于1到30之间的数字,并且取回集合(4,22,7,2).

for example. If I have a function that gives me the random set (4, 22, 7, 343, 67, 38, 2), I want to be able to say, give me the numbers from that set that are between 1 and 30, and get the set (4, 22, 7, 2) back.

推荐答案

正如RB所说,您需要加密,而不是RNG.使用给定的密钥,加密是可逆的.如果您希望从更改范围的同一种子获得不同的结果,则该键也可以合并种子和范围.

As RB said, you need an encryption, not a RNG. With a given key, the encryption is reversible. The key could incorporate the seed and the range as well if you want different results from the same seed with a changed range.

范围大小是一个不同的问题.对于32位范围,请使用DES.对于64位,请使用AES.对于其他范围,请编写您自己的简单 Feistel密码或使用

Range sizes are a different problem. For a 32 bit range use DES. For 64 bit use AES. For other ranges either write your own simple Feistel cypher or use the Hasty Pudding cypher, which is defined for all sizes.

无论您使用哪种底层密码,您都可以始终使用Hasty Pudding方法在适当范围内查找数字:只需对输出进行加密,直到其位于所需范围内.一旦您拥有合适大小的东西,就可以添加下界以获取所需的数字.因此,对于5到35的范围,您将在[0..30]中生成一个数字并加5.

Whatever underlying cypher you use, you can always use the Hasty Pudding method of finding a number in the appropriate range: just keep encyphering the output until it is within the required range. Once you have something of the appropriate size you can add the lower bound back in to get your required number. So for your range of 5 to 35, you would generate a number in [0..30] and add 5.

ETA:考虑了更多问题后,您不能将种子用作密钥的一部分.如果这样做,您将无法重建密钥以解密您的随机数.您只能在开始逆转过程时知道的密钥中使用数据.

ETA: Having thought about your problem a bit more, you can't use the seed as part of the key. If you do you won't be able to reconstruct the key to decrypt your random number. You can only use data in the key that you will know when you start reversing the process.

您还需要一种识别种子的方法.解密时,您会得到一系列数字.您需要一种方法来选择哪一个是原始种子.也许您可以将种子限制在指定的范围内(或从零开始的等效范围内),并在解密序列中选择第一个落在正确范围内的种子.

You will also need a way of recognising the seed when you come to it. As you decrypt you will get a series of numbers; you need a way to pick out which one was the original seed. Perhaps you could constrain the seed to be within the range specified (or its zero-based equivalent) and pick the first in the decryption series that falls within the correct range.

这篇关于数值,可逆,伪随机数生成器,用于非常大的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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