testReveal2.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. require_once realpath(dirname(__FILE__)) . '/../common.php';
  3. ini_set("display_errors", "On");
  4. error_reporting(E_ALL & ~E_NOTICE);
  5. //
  6. //$source = '246ad50e54c6d53d2447ff15726b6d3b7ade21cbbf4c5a128723cb1ec21f2493';
  7. //$nums = getNum($source);
  8. //var_dump($nums);exit;
  9. $objGame3 = new TableHelper('game3', 'dw_box');
  10. $games = [];
  11. for ($i = 0; $i < 500; $i++) {
  12. // $cmd = "openssl rand 32 -hex";
  13. // $source = exec($cmd);
  14. $source = '';
  15. $cmd = "openssl rand 32 -hex";
  16. $rand = rand(1, 20);
  17. for ($k = 0; $k < $rand; $k++) {
  18. $source = exec($cmd);
  19. }
  20. $cmd = "echo '$source' | xxd -r -p | shasum -a 256 -b | awk '{print $1}'";
  21. $commitment = exec($cmd);
  22. $nums = getNum($source);
  23. $games[] = [
  24. 'id' => $i,
  25. 'ttl' => 80,
  26. 'game_state' => 2,
  27. 'source' => $source,
  28. 'commitment' => $commitment,
  29. 'num1' => $nums[0],
  30. 'num2' => $nums[1],
  31. 'num3' => $nums[2],
  32. 'create_time' => date('Y-m-d H:i:s'),
  33. 'update_time' => date('Y-m-d H:i:s'),
  34. ];
  35. if (count($games) > 10) {
  36. $objGame3->replaceObjects2($games);
  37. $games = [];
  38. }
  39. }
  40. if ($games) {
  41. $objGame3->replaceObjects2($games);
  42. }
  43. function getNum($source) {
  44. $nums = [];
  45. for ($i = 0; $i < 3; $i++) {
  46. $sum = 0;
  47. for ($n = 0; $n < 6; $n++) {
  48. $index = ($i * 6 + $n) * 2;
  49. $str = $source[$index] . $source[$index + 1];
  50. $sum += hexdec($str);
  51. }
  52. $nums[] = $sum % 6 + 1;
  53. }
  54. return $nums;
  55. }