Working with large numbers in php is outputing 0 - php

I am trying to do some Diffie-Hellman which works fine with smaller generator, mod and private keys. But when the numbers get to large it just outputs zero. I've looked at other posts with no real solution. Could it be configured in php.ini?
$gen = 877;
$mod = 80182923;
$saltA = 517;
$saltB = 1517;
echo "calculation of Ga og Gb<br>";
echo "<br>user A shareable value<br>";
$calculatedSecretKeyA = ($gen**$saltA) % $mod;
echo $gen . "^" . $saltA . " mod " . $mod . " = " . $calculatedSecretKeyA;
echo "<br>user B shareable value<br>";
$calculatedSecretKeyB = ($gen**$saltB) % $mod;
echo $gen . "^" . $saltB . " mod " . $mod . " = " . $calculatedSecretKeyB;
echo "<br>user As calc of secret key <br>";
$calcKeyA = ($calculatedSecretKeyB**$saltA) % $mod;
echo $calculatedSecretKeyB . "^" . $saltA . "" . " mod " . $mod . " = " . $calcKeyA;
echo "<br><br>user Bs calc of secret key <br>";
$calcKeyB = ($calculatedSecretKeyA**$saltB) % $mod;
echo $calculatedSecretKeyA . "^" . $saltB . "" . " mod " . $mod . " = " . $calcKeyB;
echo "<br><br>bruteforcer A calc of secret key <br>";
$calcKeyB = ($calculatedSecretKeyA**7) % $mod;
echo $calculatedSecretKeyA . "^" . 7 . "" . " mod " . $mod . " = " . $calcKeyB;

You can use GMP library for this (https://www.php.net/manual/en/ref.gmp.php):
echo "calculation of Ga og Gb<br>";
echo "<br>user A shareable value<br>";
$calculatedSecretKeyA = gmp_mod ( gmp_pow ($gen, $saltA), $mod);
echo $gen . "^" . $saltA . " mod " . $mod . " = " . $calculatedSecretKeyA;
Output:
calculation of Ga og Gbuser A shareable value877^517 mod 80182923 = 79127908

Related

How does the computer calculate or store Diffie-Hellman values?

So usually the Diffie-Hellman key is 2048 bits as I understand but my computer can barely calculate a 10 digit number. What are some common numbers in Diffie-Hellman?
Here is my code that's suuuper slow:
$gen = 77;
$mod = 517165;
$saltA = 1233217;
$saltB = 5173123;
$calculatedSecretKeyA = gmp_mod(gmp_pow($gen, $saltA), $mod);
$calculatedSecretKeyB = gmp_mod(gmp_pow($gen, $saltB), $mod);
$calcKeyA = gmp_mod(gmp_pow($calculatedSecretKeyB, $saltA), $mod);
echo $calculatedSecretKeyB . "^" . $saltA . "" . " mod " . $mod . " = " . $calcKeyA;
$calcKeyB = gmp_mod(gmp_pow($calculatedSecretKeyA, $saltB), $mod);
echo $calculatedSecretKeyA . "^" . $saltB . "" . " mod " . $mod . " = " . $calcKeyB;
Use gmp_powm
gmp_powm ( GMP|int|string $num , GMP|int|string $exponent , GMP|int|string $modulus ) : GMP
for the below lines.
$calculatedSecretKeyA = gmp_powm($gen, $saltA, $mod);
$calculatedSecretKeyB = gmp_powm($gen, $saltB, $mod);
$calcKeyA = gmp_powm($calculatedSecretKeyB, $saltA, $mod);
$calcKeyB = gmp_powm($calculatedSecretKeyA, $saltB, $mod);
It uses the modular form of square-and-multiply technique. The intermediate values will never exceed mod^2. Also, it has O(log n) complexity.

Word2vec in php

I am fairly new to ML and have no idea how things work, i have a webpage with search bar. and i need to use word2vec to complete user input in search bar.
i am using this code from https://github.com/donlinglok/C-word2vec-php
<?php
$txtfilepath = fopen("options.txt", "r") or die("Unable to open file!");
echo fread($txtfilepath, filesize("options.txt"));
//fclose($txtfilepath);
function train($txtfilepath) {
$cbow = 1;
$size = 500;
$window = 10;
$negative = 10;
$hs = 0;
$sample = "1e-5";
$threads = 40;
$binary = 1;
$iter = 3;
$min_count = 10;
exec ( "cd " . dirname ( __FILE__ ) . "/google-word2vec-trunk && ./word2vec " . " -train " . $txtfilepath . " -output " . dirname ( __FILE__ ) . "/vectors.bin " . " -cbow " . $cbow . " -size " . $size . " -window " . $window . " -negative " . $negative . " -hs " . $hs . " -sample " . $sample . " -threads " . $threads . " -binary " . $binary . " -iter " . $iter . " -min-count " . $min_count, $outputArray );
}
function distance($keyword) {
exec ( "cd " . dirname ( __FILE__ ) . " && ./distancecli " . dirname ( __FILE__ ) . "/vectors.bin " . $keyword, $outputArray );
if (isset ( $outputArray[0] )) {
return $outputArray;
} else {
return distance ( $keyword );
}
}
//train ( dirname ( __FILE__ ) . "/google-word2vec-trunk/questions-words.txt" );
echo json_encode ( distance ( "facebook" ), true );
?>
what should i do next ? how to run this code and get result in search bar? i ran it from the web folder http://localhost/trainmodel/word2vec.php and recieved this error Fatal error:
Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\trainmodel\word2vec.php on line 23
You can overcome this problem by increasing the max_execution_time value in the php settings.

Authorize.Net Simple Chekout method on XML after ARB process

How can I add the 2nd time Direct Post method after payment is getting succeeded on Authorized Dot Net ARB. Let me elaborate
Suppose an user will subscribe for membership and the website will ask for donation too. After payment of Membership on ARB(XML version) how may I pay again for donation one time through Authorized dot net. I tried to use ARB and got duplicate entry error. Let me paste the code here for more details.
ARB Code I used
$SubscrName = $FirstName." ".$LastName;
$length = 12;
$unit = "months";
$totatltenure = $CardExpYear-date("Y");
$start_date = date("Y-m-d");
$totalOccurrences = 1*$totatltenure;
$trialOccurrences = 0;
$trialAmount = 0;
$expirationDate = $CardExpYear."-".$CardExpMonth;
$content =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
"<ARBCreateSubscriptionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
"<merchantAuthentication>".
"<name>" . $loginname . "</name>".
"<transactionKey>" . $transactionkey . "</transactionKey>".
"</merchantAuthentication>".
"<refId>" . $refId . "</refId>".
"<subscription>".
"<name>" . $SubscrName . "</name>".
"<paymentSchedule>".
"<interval>".
"<length>". $length ."</length>".
"<unit>". $unit ."</unit>".
"</interval>".
"<startDate>" . $start_date . "</startDate>".
"<totalOccurrences>". $totalOccurrences . "</totalOccurrences>".
"<trialOccurrences>". $trialOccurrences . "</trialOccurrences>".
"</paymentSchedule>".
"<amount>". $TotalCosting ."</amount>".
"<trialAmount>" . $trialAmount . "</trialAmount>".
"<payment>".
"<creditCard>".
"<cardNumber>" . $CardNumber . "</cardNumber>".
"<expirationDate>" . $expirationDate . "</expirationDate>".
"<cardCode>".$CVV_Code."</cardCode>".
"</creditCard>".
"</payment>".
"<billTo>".
"<firstName>". $CardFirstName . "</firstName>".
"<lastName>" . $CardLastName . "</lastName>".
"<address>" . $CardStreet . "</address>".
"<city>" . $CardCity . "</city>".
"<state>" . $CardState . "</state>".
"<zip>" . $CardZip . "</zip>".
"</billTo>".
"</subscription>".
"</ARBCreateSubscriptionRequest>";
$response = send_request_via_curl($host,$path,$content);
if ($response)
{
list ($refId, $resultCode, $code, $text, $subscription_id) =parse_return($response);
if($resultCode == "Ok")
{
if($_SESSION['willdonate'] == 'donated' && $_SESSION['donateammount'] != '')
{
$SubscrName = $FirstName." ".$LastName;
$length = 2;
$unit = "months";
$totatltenure = 1;
$start_date = date("Y-m-d");
$totalOccurrences = 1;
$trialOccurrences = 0;
$trialAmount = 0;
$expirationDate = date("Y-m");
$TotalCosting = $_SESSION['donateammount'];
$contentDonation =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
"<ARBCreateSubscriptionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
"<merchantAuthentication>".
"<name>" . $loginname . "</name>".
"<transactionKey>" . $transactionkey . "</transactionKey>".
"</merchantAuthentication>".
"<refId>" . $refId . "</refId>".
"<subscription>".
"<name>" . $SubscrName . "</name>".
"<paymentSchedule>".
"<interval>".
"<length>". $length ."</length>".
"<unit>". $unit ."</unit>".
"</interval>".
"<startDate>" . $start_date . "</startDate>".
"<totalOccurrences>". $totalOccurrences . "</totalOccurrences>".
"<trialOccurrences>". $trialOccurrences . "</trialOccurrences>".
"</paymentSchedule>".
"<amount>". $TotalCosting ."</amount>".
"<trialAmount>" . $trialAmount . "</trialAmount>".
"<payment>".
"<creditCard>".
"<cardNumber>" . $CardNumber . "</cardNumber>".
"<expirationDate>" . $expirationDate . "</expirationDate>".
"<cardCode>".$CVV_Code."</cardCode>".
"</creditCard>".
"</payment>".
"<billTo>".
"<firstName>". $CardFirstName . "</firstName>".
"<lastName>" . $CardLastName . "</lastName>".
"<address>" . $CardStreet . "</address>".
"<city>" . $CardCity . "</city>".
"<state>" . $CardState . "</state>".
"<zip>" . $CardZip . "</zip>".
"</billTo>".
"</subscription>".
"</ARBCreateSubscriptionRequest>";
$responseDonation = send_request_via_curl($host,$path,$contentDonation);
if ($responseDonation)
{
var_dump($responseDonation);
exit;
list ($refId, $resultCodeDonation, $code, $text, $subscription_id) =parse_return($responseDonation);
if($resultCodeDonation == "Ok")
{}
}
}
}
}
Here is the code I have used where I tried ARB Script two times to pay 2nd time but I think this is not the right process so I get an error of Duplicate entry. Can anyone help me providing XML CUrl code of Direct Post method like ARB XML Curl I used. I didn't find any suitable example after searching a lot.

displaying multidimensional array

How do you display the output of a 2 dimensional arrays
Here's the code:
I know how to display both of them separately doing.
foreach($Father as $value){
echo $value[0] . " " . $value[1] . "<br />";
}
foreach($Son as $value){
echo $value[0] . " " . $value[1] . "<br />";
}
try this - it assumes that each father has exactly 1 son though
$i = 0;
foreach($Father as $value){
echo $value[0] . " " . $value[1] . "<br />";
echo "-" . $Son[$i][0] . " " . $Son[$i][1] . "<br />";
$i += 1;
}

Using arrays in PHP

I am working on my first program written in PHP. This is a basic question. I am trying to print a string stored in an array. I have two arrays. One array, $content, stores a number at $content[$i][15] (i am using arrays in arrays, and looping through it with a for loop). Lets say this number is 3. I now want to access a string in another array, called $type. This string is at position $type[3]. Logically, I think, $type[3] should print the same thing as $type[$content[$i][15]]. But, when I call $type[$content[$i][15]], it doesn't print anything, but when i print $type[3] it works fine. Is this type of call not allowed in PHP?
$type = array();
$typetemp = readfile("type.csv");
foreach ($typetemp as $sa){
$type[$sa[0]] = $sa[1];
}
$content = readfile("content.csv");
for($i=0; $i<sizeof($content); $i++){
if($content[$i][15] == 3){
if($content[$i][4] == 1){
$temp = $content[$i][15];
echo "id is " . $content[$i][0] . "title is " . $content[$i][1] . "introtext is " . $content[$i][2] . "restoftext is " . $content[$i][3] . "visible is " . $content[$i][4] . "category is " . $content[$i][5] . "creation_date is " . $content[$i][6] . "author is " . $content[$i][7] . "img is " . $content[$i][8] . "ordering is " . $content[$i][9] . "rank is " . $content[$i][10] . "vid is " . $content[$i][11] . "start_date is " . $content[$i][12] . "stop_date is " . $content[$i][13] . "event_date is " . $content[$i][14] . "type is " . $content[$i][15] . "thumb is " . $content[$i][16] . "type name is " . $type[$temp] . "<br/>";
}
}
}
function readfile($filename) {
$line_of_text = array();
$file_handle = fopen($filename, "r");
while (!feof($file_handle) ) {
array_push($line_of_text, fgetcsv($file_handle, 1024));
}
fclose($file_handle);
return $line_of_text;
}
You are missing a $ sign before content:
$type[$content[$i][15]]
This accesses the value in $type with index $content[$i][15]

Categories