dongzuo7166 2017-02-03 00:17
浏览 79
已采纳

通过拥有许多输出来预测PHP rand()

I was wondering if it possible to predict the next pseudo random number that will be generated out of PHP rand() function, by using the previous outputs of it.

An example would be that I have n outputs of rand(1,10) like 8, 5, 10, 3, 3, 2 ... 9, 8 ... and so on.

So the question is, is there any way that I can use these already generated numbers to predict the next one?

EDIT

Since the question was marked as too broad, I will try to be more specific. Can I predict the next RGN or recover the seed, on PHP running on Linux, when using the rand() function, by only observing some outputs given from it.

A concrete example is the following output:

21962

10038

10425

17032

Generated by the following code:

<?php
echo rand(1, 68703);
  • 写回答

1条回答 默认 最新

  • douxin8749 2017-02-03 03:27
    关注

    Not sure what is under the hood, but it is likely covered by one of these links:

    If it is not covered, then provide me the source code and I will break it.

    EDIT: As requested in comments below, I update my answer.

    One trivial way to break it is brute force search of the srand seed. Normally this is a 32-bit int (which will take a few minutes to brute force), but on some platforms it may be 64-bit (takes too long to break via brute force). So you just loop through each candidate seed, do srand( candidate seed) and then generate your rand(1, 68703) to see if it matches the outputs. If so, you presumably have the right seed and can generate future outputs. Otherwise continue loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)