【发布时间】:2019-10-17 21:44:21
【问题描述】:
我们需要在伪随机数生成器中实现 Blum Blum Shub 算法。我尝试在 c# 中搜索实现以获得一个想法,但没有成功。我们需要实施的一些方法不够清楚(或者我可能没有得到他们所要求的确切内容)。
任何人都可以为代码或类似方式的示例提供一些帮助吗?我很难从文本中掌握概念。任何帮助都会被极大地接受!
首先,我尝试遵循问题的逻辑。由于进展不大,我开始在网上搜索更好的解释,并可能找到实现更好的理解。最后,我尝试用我认为有意义的方式填写一些请求的方法。
static long seed = 6367859;
static long p = 3263849;
static long q = 1302498943;
static long m = p*q;
// Generates a random bit i.e. 0 or 1 using the Blum Blum Shub Algorithm and the Least Significant Bit
private byte generateRandomBit(){ }
// Method to generate a single positive 32 bit random number using the Blum Blum Shub Algorithm.
// The generateRandomBit() method is used to generate the random bits that make up the random number
// Not complete!!
public int GenerateNextRandomNumber()
{
int nextRandomNumber = (int)((p * seed + q) % m);
seed = nextRandomNumber;
return nextRandomNumber;
}
// Generates a random number between min and max.
// The GenerateNextRandomNumber() method must be used to generate the initial random number which must then be manipulated (if necessary) to be between min and max
public int GenerateNextRandomNumber(int min, int max){ }
// Uses the GenerateNextRandomNumber Method to generate a sequence of Random Numbers between the minimum and the maximum value using the Blum Blum Shub Algorithm
public int[] GenerateRadmonSequence(int n, int min, int max)
{
int[] sequence = new int[n];
for (int i = 0; i < n; i++)
{
int randNum = Math.Abs(GenerateNextRandomNumber());
randNum = min + randNum % (max + 1 +- min);
sequence[i] = randNum;
}
return sequence;
}
结果应该是生成一个从min到max的数字序列。
【问题讨论】:
-
很抱歉,如果不清楚。我正在尝试在如上所示的伪随机数生成器中实现 Blum Blum Shub,但在描述我需要在其中做什么的 cmets 上苦苦挣扎。我的问题主要是让自己熟悉算法,因为我在 c# 中找不到实现。
-
Blum Blum Shub from Wikipedia: Blum Blum Shub 采用 x[n + 1] = (x[n] ^ 2) % M 的形式,其中 M 是两个大素数的乘积。
-
参见Handbook of Applied Cryptography 第 5 章,第 5.5.2 节。
标签: c# random numbers generator