Skip to content

Commit

Permalink
Merge pull request #2 from AKaravas/changes
Browse files Browse the repository at this point in the history
small changes
  • Loading branch information
AKaravas committed Nov 4, 2020
2 parents 64291f8 + 7754d14 commit 2b1115e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Classes/DecodeShareCode.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


/**
* Class DecodeShareCode
* @package
*/
class DecodeShareCode
{
Expand Down Expand Up @@ -47,9 +45,9 @@ public function decode(string $shareCode): array
$portBytes = array_reverse(array_slice($bytes, 16, 2));

return [
'matchId' => $getMatchId = $this->getResultFromBytes($matchIdBytes),
'reservationId' => $getReservationId = $this->getResultFromBytes($reservationIdBytes),
'tvPort' => $getPort = $this->getResultFromBytes($portBytes)
'matchId' => $this->getResultFromBytes($matchIdBytes),
'reservationId' => $this->getResultFromBytes($reservationIdBytes),
'tvPort' => $this->getResultFromBytes($portBytes)
];
}

Expand Down Expand Up @@ -80,8 +78,7 @@ public function getDecodedBigNumber(): string
*/
public function convertToHex(string $number): string
{
$toHex = gmp_strval(gmp_init($number, 10), 16);

$toHex = gmp_strval(gmp_init($number, 10), 16);;
return $this->padStart($toHex, '36', '0');

}
Expand Down Expand Up @@ -121,14 +118,19 @@ public function getResultFromBytes(array $bytes): string
$chars = array_map("chr", $bytes);
$bin = implode($chars);
$hex = bin2hex($bin);
return gmp_strval($this->gmp_hexdec($hex));
return gmp_strval($this->gmp_hexDec($hex));
}

public function gmp_hexdec($n) {
/**
* @param $n
* @return string
*/
public function gmp_hexDec($n): string
{
$gmp = gmp_init(0);
$mult = gmp_init(1);
for ($i=strlen($n)-1;$i>=0;$i--,$mult=gmp_mul($mult, 16)) {
$gmp = gmp_add($gmp, gmp_mul($mult, hexdec($n[$i])));
$multi = gmp_init(1);
for ($i=strlen($n)-1;$i>=0;$i--,$multi=gmp_mul($multi, 16)) {
$gmp = gmp_add($gmp, gmp_mul($multi, hexdec($n[$i])));
}
return $gmp;
}
Expand Down

0 comments on commit 2b1115e

Please sign in to comment.