0

Using Mersenn Twister code(.js file) i got from official site, I have got the random numbers and sending it to (.bin or text)file using php fwrite. I am using diehard test to test that file, but every time I am testing, I am getting P value =1.00000 (It means test failed). The values I am getting are unique, but I am unable to understand, why the test fails. I receive all values as string with comma(,) bwtween the numbers. I then explode by comma(,) and add directly to file. I am saving the numbers in the below format. I have feeling that. this is not the correct procedure to save the values in a file and test.

299131238230621197891228959102184026861097431958029673278422367878886308872705730900956992109339754181722841133501937214212350166176490672129413213122489768049206558681460108395116841319131722357280147393835026943060163131244655139221749718836534591051233102256314621298395075617095870402550791376316966611627135260657837960231890890179753559554359602516228299575130594348182284182100183765969527247313841278957501364828177621134880073111511913317954877126243260121536434012310287070817919030781387097953281200661315538704541605464926980383131100722512212614921934243407436271002180032899275553955876903337208645186273235212018157918505414747469228102120361354661778198182892718133108392213411517163821944079183116490732228519953837077245297814423640551364142198006964215537210219940161092679857523244139125849657723212994400061362730766213592499117816650122934591847372076948339371908381075697607467846273207461636321281210184232947045100002271122311716091876302258263236194032278526005180961772065415948354910670634262174252590123521121419985923410492601861517173147215946541907504130618885614637076111791096753296040072629261644833733912643376005850711502086612192247257196171735128746808091152259426251657830735951143792683940099116185163528977674162276599006361783322275321984935731976713527705743279992806382728443510465391297745384388341812602123071926245868393191181341441108212922371491173802449774687624010269401379539473189003107049571427044268969274415204890366125530654881330939525239137418421784259656827264861205997614657432847328065362729872765844661856251369091373219754027329719897603907429795238105794993791782516705300031559520068397341379036720802633614945117305540451815350108761687683393187223924993432318130896890816328379551710194476235863326730277751112391090150427503215217758150152864270127402858523275117932247596351254767547618479914029708365993758316016649087456125665420117131606163276062

The php code I am using to write data in a file is

<?php

$Text = $_POST["first"];
$arr = array();
$arr = NULL;
unset($arr);
$arr = explode(",",$Text);
$myFile = "test1.bin";
echo sizeof($arr);
$fh = fopen($myFile, 'wb') or die("can't open file"); 
for($i=0;$i<sizeof($arr);$i++)
{
    //$val= dechex($arr[$i]);
    $sd=pack(V,$arr[$i]); 
    fwrite($fh,$sd);
    if($i % 10==9)
    {

     }
     //$sd=pack(V,$arr[$i]); 
}
fwrite($fh,$str);
fclose($fh);
?>

Note: I am using .bin file, so I can test using diehard test. The vales I have mentioned above are from same code, but written in txt file, to show you, how I am writing the values in a file.

user1647017
  • 283
  • 1
  • 2
  • 14
  • Have you tested this in isolation before, i.e. without the JavaScript component? – Ja͢ck Apr 29 '13 at 09:17
  • The code is fine..., and the output I am getting is also correct(as per my knowledge, pardon me if I am wrong). The above code has no errors I just want to know, how to write the data(i.e random values) in the file.., is there any type of conditions provided, so that gets true, then only the code will pass diehard test somthing like that. – user1647017 Apr 29 '13 at 09:28
  • there should be apostrophes in `$sd=pack("V",$arr[$i]);` and then those three commands `$arr = array(); $arr = NULL; unset($arr);` are there redundant – Stano Apr 29 '13 at 10:11
  • Hi @Stano Even that dint work..., – user1647017 Apr 29 '13 at 12:14
  • how big is the file? you need lots of numbers. – Nishanth Apr 29 '13 at 15:46
  • Hi, so is it that `$_POST["first"]` is a string containing generated numbers from 0 to 2^32, like e.g. "323231,131212,73279,312,21501,..." and you want to convert those numbers from a string to 4Byte integers, then write them to that output .bin file? – Stano Apr 29 '13 at 21:06
  • The file is of size 10mb and @Stano yes, you are right, I am trying the same, but the test is failing... I am unable get to the point of this problem. – user1647017 Apr 30 '13 at 04:21
  • It seems to me there are too many 0xFF generated patterns in that output file... tested it like this: http://ulozto.net/xcM4VTTd/mersenne-twister-zip – Stano Apr 30 '13 at 08:18
  • @Stano Please dont mind.. can you tell me, what was the problem in my code, as I observed that we both are inserting values in same procedure. – user1647017 Apr 30 '13 at 11:48
  • Hello, tested your code on localhost. I dunno what was wrong, used php's function `var_export($_POST);` to see, whether those javascript generated numbers are correctly separated by commas and looked at the output file in hexaviewer (10.000 integers created 40.000 Bytes file, so it seems to be ok) I didn't test it with diehard tests, i am not a cryptography specialist. – Stano Apr 30 '13 at 14:27
  • Hello @Stano , thanks for your support and help. It was a big relief to know that the code I have written is not wrong. There may be some other issue, which I haven't observed. – user1647017 May 01 '13 at 06:06

0 Answers0