/** * Attributes decoding test */ public function testDecodeAttributes() { $decoder = new Decoder(); $attributes = $decoder->decode(array('"Hello"', array('name' => 'href', 'value' => '/'), array('name' => 'data-id', 'value' => 34), array('name' => 'first-name', 'value' => "'Bob'"), array('name' => 'last-name', 'value' => '"Dylan"'), array('name' => 'checked', 'value' => true))); $this->assertSame($attributes[0], 'Hello'); $this->assertSame($attributes[1]['value'], '/'); $this->assertSame($attributes[2]['value'], 34); $this->assertSame($attributes[3]['value'], 'Bob'); $this->assertSame($attributes[4]['value'], 'Dylan'); $this->assertSame($attributes[5]['value'], true); }
/** * @covers \Magento\Framework\Url\Encoder::encode * @covers \Magento\Framework\Url\Decoder::decode */ public function testDecode() { $urlBuilderMock = $this->getMock('Magento\\Framework\\UrlInterface', [], [], '', false); /** @var $urlBuilderMock \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ $decoder = new Decoder($urlBuilderMock); $encoder = new Encoder(); $data = uniqid(); $result = $encoder->encode($data); $urlBuilderMock->expects($this->once())->method('sessionUrlVar')->with($this->equalTo($data))->will($this->returnValue($result)); $this->assertNotContains('&', $result); $this->assertNotContains('%', $result); $this->assertNotContains('+', $result); $this->assertNotContains('=', $result); $this->assertEquals($result, $decoder->decode($result)); }
public function search() { require_once 'src/Fetcher.php'; require_once 'src/Decoder.php'; $q = null; $results = []; if (isset($_GET['q'])) { $q = $_GET['q']; $fetcher = new Fetcher(); if ($text = $fetcher->search($q)) { $decoder = new Decoder(); $results = $decoder->decode($text); } } include_once 'html/index.html'; }
/** * @covers PHP\BitTorrent\Decoder::decodeFile */ public function testDecodeFileWithStrictChecksEnabled() { $list = $this->decoder->decodeFile(__DIR__ . '/_files/valid.torrent', true); $this->assertInternalType('array', $list); $this->assertArrayHasKey('announce', $list); $this->assertSame('http://trackerurl', $list['announce']); $this->assertArrayHasKey('comment', $list); $this->assertSame('This is a comment', $list['comment']); $this->assertArrayHasKey('creation date', $list); $this->assertEquals(1323713688, $list['creation date']); $this->assertArrayHasKey('info', $list); $this->assertInternalType('array', $list['info']); $this->assertArrayHasKey('files', $list['info']); $this->assertSame(5, count($list['info']['files'])); $this->assertArrayHasKey('name', $list['info']); $this->assertSame('PHP', $list['info']['name']); }
/** * Decodes the given $encodedValue string which is * encoded in the JSON format * * Uses ext/json's json_decode if available. * * @param string $encodedValue Encoded in JSON format * @param int $objectDecodeType Optional; flag indicating how to decode * objects. See {@link Zend_Json_Decoder::decode()} for details. * @return mixed */ public static function decode($encodedValue, $objectDecodeType = self::TYPE_ARRAY) { $encodedValue = (string) $encodedValue; if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) { $decode = json_decode($encodedValue, $objectDecodeType); // php < 5.3 if (!function_exists('json_last_error')) { if ($decode === $encodedValue) { throw new Exception('Decoding failed'); } // php >= 5.3 } elseif (($jsonLastErr = json_last_error()) != JSON_ERROR_NONE) { switch ($jsonLastErr) { case JSON_ERROR_DEPTH: throw new Exception('Decoding failed: Maximum stack depth exceeded'); case JSON_ERROR_CTRL_CHAR: throw new Exception('Decoding failed: Unexpected control character found'); case JSON_ERROR_SYNTAX: throw new Exception('Decoding failed: Syntax error'); default: throw new Exception('Decoding failed'); } } return $decode; } return Decoder::decode($encodedValue, $objectDecodeType); }
<?php require_once 'src/Encoder.php'; require_once 'src/Decoder.php'; $iBase = $_POST['base']; $sOption = $_POST['option']; $sText = file_get_contents($_FILES['arquivo']['tmp_name']); if (empty($sText)) { throw new Exception("Erro ao Ler o arquivo"); } if ($sOption == 'encoder') { $oEncoder = new Encoder($iBase, $sText); $sOutputFile = $oEncoder->process(); } else { $oDecoder = new Decoder($iBase, $sText); $sText = $oDecoder->process(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </head> <body>
/** * Decodes a NEON string. * @param string * @return mixed */ public static function decode(string $input) { $decoder = new Decoder(); return $decoder->decode($input); }
/** * Decode a bencode encoded string * * @param string $string The string to decode. * @param string $decodeType Flag used to indicate whether the decoded * value should be returned as an object or an array. * @return mixed Returns the appropriate data type for the decoded data. */ public static function decode($string, $decodeType = self::TYPE_ARRAY) { return Decoder::decode($string, $decodeType); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Json decode error */ public function testJsonErrorOnDecode() { $json = 'invalid json'; Decoder::decode($json); }
/** * @param mixed $to * @return Message */ public function setTo($to) { $address = Decoder::getAddress($to); $this->toName = $address->getName(); $this->toEmail = $address->getEmail(); return $this; }
public function __construct($options = array()) { parent::__construct(array_merge(array('dictionary' => SoapConstants::buildDictionary()), $options)); }
if (isset($request->action) && isset($request->data) && isset($request->rot)) { if ($request->action === 'encode') { // Receiving encoded text $response['data'] = Encoder::encode($request->data, (int) $request->rot); // Receiving input frequency $response['frequency'] = Encoder::getFrequency($request->data); // Setting success status $response['status'] = 'success'; // Setting solution attempt $response['solution'] = Solver::tryGuess($request->data); } else { if ($request->action === 'decode') { // Receiving decoded text $response['data'] = Decoder::decode($request->data, (int) $request->rot); // Setting success status $response['frequency'] = Decoder::getFrequency($request->data); // Setting success status $response['status'] = 'success'; // Setting solution attempt $response['solution'] = Solver::tryGuess($request->data); } else { // Default for external POST requests //Setting error message $response['error'] = 'Wrong params for Caesar code'; // Setting fail status $response['status'] = 'fail'; } } } // Server json output echo json_encode($response);
public static function tryGuess($str) { $result = array(); if (self::isEnglish($str) > 50) { $result['eng']['message'] = 'This is an english text with the probability '; $result['eng']['probability'] = self::isEnglish($str); return json_encode($result); } else { for ($i = 0; $i < 26; $i++) { $dec = Decoder::decode($str, $i); $prob = self::isEnglish($dec); if ($prob > 40) { $result[$i]['rot'] = $i; $result[$i]['probability'] = $prob; $result[$i]['decoded'] = $dec; } } return count($result) ? json_encode($result) : json_encode(array('message' => 'Unfortunately, there is no matches for this text yet!')); } }
/** * @test * * @covers Lcobucci\JWT\Parsing\Decoder::base64UrlDecode */ public function base64UrlDecodeMustReturnTheRightData() { $data = base64_decode('0MB2wKB+L3yvIdzeggmJ+5WOSLaRLTUPXbpzqUe0yuo='); $decoder = new Decoder(); $this->assertEquals($data, $decoder->base64UrlDecode('0MB2wKB-L3yvIdzeggmJ-5WOSLaRLTUPXbpzqUe0yuo')); }
/** * @param $value * @param int $type * @return mixed * @throws JsonDecodingException */ public static function decode($value, $type = self::TYPE_OBJECT) { $decoder = new Decoder($type); return $decoder->decode($value); }