function SetupRender() { if (isset($_POST['install_base64']) || isset($_POST['uninstall_base64'])) { $this->SetupExecute(); } else { $out = "This plugin allows you to install and uninstall a base64 custom function to and from your database.\n\t\t\tYou can then set \$configuration['db_encoding'] = 1 so that all data is transparently encoded and decoded\n\t\t\twith the minimal overhead possible. Enabling data encoding has quite a few advantages: <br/><br/>\n\n\t\t\t"; $out .= "<br/><br/><textarea>BASE64 Status"; if (Base64::IsBase64FunctionInstalled()) { $out .= "\n\tChecking MySQL function....OK!"; if (!isset($GLOBALS['configuration']['db_encoding']) || $GLOBALS['configuration']['db_encoding'] != 1) { $out .= "\n\tChecking db_encoding status....Failed"; $out .= "\n\n---------------------------------------------------"; $out .= "\n\$configuration['db_encoding'] is set to 0. Make sure you set the value to 1 to enable data encoding."; } else { $out .= "\n\tChecking db_encoding status....OK!"; $out .= "\n\nBASE64 Status...OK!"; $out .= "\n---------------------------------------------------"; } $out .= "</textarea><div style='padding-left:250px;padding-top:10px;'><input type='submit' value='UNINSTALL' name='uninstall_base64'/></div>"; } else { $out .= "\n\tChecking MySQL function....NOT INSTALLED"; $out .= "\n\tChecking db_encoding status ignored"; $out .= "\n\n---------------------------------------------------"; $out .= "\nClick the INSTALL button below to install the base64 function to your database."; $out .= "</textarea><div style='padding-left:250px;padding-top:10px;'><input type='submit' value='INSTALL' name='install_base64'/></div>"; } $out .= "<input type='hidden' name='plugins' value='true'/>"; echo $out; } }
/** * Add an autoRun entry. * * @param array $run * @param string $workspace * @string file * @return bool * @throws \Error */ protected function addautoRun(array $run, string $workspace, string $file) : bool { static $db_tpl = null; if ($db_tpl === null) { $db_tpl = \file_get_contents(\dirname(HANGAR_ROOT) . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'index.php.tmp'); } $hash = Util::hash($file); switch ($run['type']) { case 'php': \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun' . DIRECTORY_SEPARATOR . $hash . '.php', Base64::decode($run['data'])); \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun.php', 'require_once __DIR__ . DIRECTORY_SEPARATOR . "autoRun" . DIRECTORY_SEPARATOR . "' . $hash . '.php";' . "\n", FILE_APPEND); return true; case 'mysql': case 'pgsql': $exec = \str_replace(['@_QUERY_@', '@_DRIVER_@'], [\str_replace('"', '\\"', Base64::decode($run['data'])), $run['type']], $db_tpl); // Save the template file: \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun' . DIRECTORY_SEPARATOR . $hash . '.php', $exec); // Add the autoRun script to the autoRun list: \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun.php', 'require_once __DIR__ . DIRECTORY_SEPARATOR . "autoRun" . DIRECTORY_SEPARATOR . $hash . ".php";' . "\n", FILE_APPEND); return true; default: throw new \Error('Unknown type: ' . $run['type']); } }
public function testDecode() { $this->assertEquals('f', Base64::decode('Zg==')); $this->assertEquals('fo', Base64::decode('Zm8=')); $this->assertEquals('foo', Base64::decode('Zm9v')); $this->assertEquals('foob', Base64::decode('Zm9vYg==')); $this->assertEquals('fooba', Base64::decode('Zm9vYmE=')); $this->assertEquals('foobar', Base64::decode('Zm9vYmFy')); }
public function unserialize($signed_data) { if (!is_scalar($signed_data)) { return NULL; } if (strpos($signed_data, '.') === FALSE) { return NULL; } list($encoded_sig, $payload) = explode('.', $signed_data, 2); $sig = self::base64UrlDecode($encoded_sig); $data = parent::unserialize($payload); $expected_sig = hash_hmac('sha256', $payload, $this->__secret, $raw = true); if ($sig !== $expected_sig) { return NULL; } return $data; }
function afterFind($type, &$data) { if (!empty($data) and is_array($data)) { $fresh_models = false; $_items = array_values($data); if ($data === $_items and !empty($_items[0][$this->alias])) { //this is a modeled data array $fresh_models = true; $this->_get_params_fields(); } $models_list = array_merge(array($this->alias), array_keys($this->hasOne), array_keys($this->belongsTo)); foreach ($data as $k => $record) { if ($fresh_models) { $models_list = array_keys($record); } foreach ($models_list as $model) { if (!empty($data[$k][$model])) { if (isset($data[$k][$model]['extras'])) { $extras = new Base64($data[$k][$model]['extras']); $data[$k][$model]['extras'] = $extras->decode(); } foreach ($this->params_fields as $params_field) { if (isset($data[$k][$model][$params_field])) { $params = new Parameter($data[$k][$model][$params_field]); $data[$k][$model][$params_field] = $params->toArray(); } } if (!in_array($model, array('TagItem', 'Tag')) and !empty($this->hasMany['TagItem']) and isset($data[$k]['Tag'])) { $tags = !is_null(Arr::getVal($data[$k]['Tag'], array('[n]', 'title'))) ? Arr::getVal($data[$k]['Tag'], array('[n]', 'title')) : array(); $data[$k][$model]['tags'] = implode(',', $tags); } } } } } }
/** * @fn function valid_key($key, $username, $cleartext) * @short Singular license validator */ public static function valid_key($key, $username = '', &$cleartext = NULL) { $valid = FALSE; if (strlen($key) > 0 && strlen($username) > 0) { // Convert from ISO-8859-1 to UTF-8 $username = iconv("iso-8859-1", "utf-8", $username); // Calculate SHA-1 hash $hash = sha1($username); // $raw_key = Base64::decode($key); $pub_key_path = dirname(__FILE__) . "/../openssl/singular_public_key.pem"; if (file_exists($pub_key_path)) { $fp = fopen($pub_key_path, "r"); $pub_key = fread($fp, filesize($pub_key_path)); fclose($fp); if (($res = openssl_get_publickey($pub_key)) !== FALSE) { /* * NOTE: Here you use the returned resource value */ openssl_public_decrypt($raw_key, $cleartext, $res); $cleartext_parts = explode(';', $cleartext); $valid = $cleartext_parts[0] == $hash; } } } return $valid; }
/** * Generate a Response for the 404 Exception. * * The user should be shown a nice 404 page. * * @return Response */ public function get_response() { $url = Route::get('error')->uri(array('action' => 404, 'message' => Base64::encode_to_url($this->getMessage()))); $body = Request::factory($url)->execute(); return Response::factory()->status(404)->body($body); }
<?php include_once 'config.php'; include_once 'base64.php'; error_reporting(E_ALL); $base64 = new Base64(); //alfa - параметр зашифрованной строки if (!isset($_REQUEST['alfa'])) { exit; } //--- получение параметров из строки $alfa = $_REQUEST['alfa']; $params = $base64->decode($alfa, $CRYPT_KEY, true); parse_str($params); //--- проверка параметров if (!isset($login) || !isset($password) || !isset($symbol)) { $str_result = "error=" . ERR_WRONG_REQUEST; $str_result .= "&error_desc=2"; $str_result .= "&end=" . time(); $str_result = $base64->encode($str_result, $CRYPT_KEY, true); echo 'omega=' . $str_result; exit; } //--- выборка user из USERS $query = "SELECT `id`, `exp_time` FROM `" . $DB_TABLE_USERS . "` WHERE `login`='{$login}' AND `password`='{$password}'"; $result = mysql_query($query); $errno = mysql_errno(); //--- ошибка в запросе if ($errno > 0) { $str_result = "error=" . (ERR_MYSQL_ERROR_FIRST + $errno); $str_result .= "&error_desc=" . mysql_error();
public function testEncodedStringIsTrimmed() { $base64 = Base64::deserialize("\nc3RyaW5n "); $this->assertSame('string', $base64->getDecoded()); $this->assertSame('c3RyaW5n', $base64->getEncoded()); }
/** * @fn get_credentials * @short Returns a set of credentials previously stored into a cookie with Base64 encoding. */ protected function get_credentials() { $parts = array('', '', ''); if (($encoded = Cookie::get('_vc')) !== NULL) { $credentials = Base64::decode($encoded); $parts = explode('%%', $credentials); } return array_combine(array('realname', 'email', 'url'), $parts); }
<?php session_start(); require_once "../../config.php"; require_once APP_PATH . "admin/includes/templates/main.tpl.php"; if (!isset($_SESSION['user_id']) || $_SESSION['email'] != SYSTEM_ADMIN_EMAIL) { header('Location: ../login.php'); } if ($_FILES) { require_once APP_PATH . "api/classes/base64.inc.php"; $uploadedFile = $_FILES['encodeFile']['tmp_name']; $uploadedFileSize = filesize($uploadedFile); $encoded = "<div style='margin-top: 30px; text-align: center;'>"; if ($uploadedFileSize) { if ($uploadedFileSize <= 1048576) { $base64 = new Base64(); $encoded .= "<span class='fileHeading'>" . $_FILES['encodeFile']['name'] . " (" . $uploadedFileSize . ") bytes</span><br /><textarea readonly='readonly' onfocus='this.select(); return false;' onclick='this.select(); return false;'>" . $base64->encode($uploadedFile) . "</textarea>"; } else { $encoded .= "<span class='error'>File must be no larger than 1MB.</span>"; } } else { $encoded .= "<span class='error'>There was an error encoding the file.</span>"; } $encoded .= "</div>"; } /***********************MAIN*********************/ $template = new MainTemplate(); $data['title'] = APP_NAME . " Admin"; $data['headerTitle'] = APP_NAME . " - Admin"; $data['menu'] = "divBase64Encoder"; $data['content'] = "\n <div style='width: 300px; margin: 20px auto 0 auto; text-align: center;'>\n <form method='post' enctype='multipart/form-data' action=''>\n <span class='fileHeading'>File:</span> <input type='file' name='encodeFile' /><br /><br />\n <input type='submit' value='Encode File' />\n </form>\n </div>\n " . $encoded;
/** * RFC 4648 Base32 decoding * * @param $str * @return string */ public static function base64Decode(string $str) : string { return Base64::decode($str); }
/** * Hash a string and store its hash in the Content-Security-Policy header * * @param string $str The data we are hashing * @param string $dir The CSP Directive * @param string $algo Which hash algorithm? * @return string $str */ function csp_hash_str(string $str, string $dir = 'script-src', string $algo = 'sha384') : string { $state = State::instance(); if (isset($state->CSP)) { if ($state->CSP instanceof CSPBuilder) { $preHash = \hash($algo, $str, true); $state->CSP->preHash($dir, Base64::encode($preHash), $algo); return $str; } } return $str; }
/** * Parse a signed JSON response * * @param Response $response * @param SignaturePublicKey $publicKey * @return mixed * @throws SignatureFailed * @throws TransferException */ public function parseSignedJSON(Response $response, SignaturePublicKey $publicKey) { $code = $response->getStatusCode(); if ($code >= 200 && $code < 300) { $body = (string) $response->getBody(); $firstNewLine = \strpos($body, "\n"); // There should be a newline immediately after the base64urlsafe-encoded signature if ($firstNewLine !== self::ENCODED_SIGNATURE_LENGTH) { throw new SignatureFailed(\sprintf("First newline found at position %s, expected %d.\n%s", \print_r($firstNewLine, true), \print_r(self::ENCODED_SIGNATURE_LENGTH, true), Base64::encode($body))); } $sig = Base64UrlSafe::decode(Binary::safeSubstr($body, 0, 88)); $msg = Binary::safeSubstr($body, 89); if (!Asymmetric::verify($msg, $publicKey, $sig, true)) { throw new SignatureFailed(); } return \Airship\parseJSON($msg, true); } throw new TransferException(); }
/** * Decode header if necessary * * @param string $header * @return string */ protected function decode($header) { if (preg_match('/^=\\?([^\\?]+)\\?([QB])\\?([^\\?]+)\\?=$/', $header, $matches)) { if ('Q' === $matches[2]) { return iconv($matches[1], xp::ENCODING, QuotedPrintable::decode($matches[3])); } else { if ('B' === $matches[2]) { return Base64::decode($matches[3]); } else { throw new FormatException('Cannot decode header "' . $header . '"'); } } } return $header; }
/** * Generate, store, and return the index and token * * @param string $lockTo What URI endpoint this is valid for * @return string[] */ protected function generateToken(string $lockTo) : array { $index = Base64::encode(\random_bytes(18)); $token = Base64::encode(\random_bytes(33)); $this->session[$this->sessionIndex][$index] = ['created' => \intval(\date('YmdHis')), 'uri' => isset($this->server['REQUEST_URI']) ? $this->server['REQUEST_URI'] : $this->server['SCRIPT_NAME'], 'token' => $token]; if (\preg_match('#/$#', $lockTo)) { $lockTo = Binary::safeSubstr($lockTo, 0, Binary::safeStrlen($lockTo) - 1); } $this->session[$this->sessionIndex][$index]['lockTo'] = $lockTo; $this->recycleTokens(); return [$index, $token]; }
/** * Decodes the quicklogin string, and returns the encripted data in plain * @param string $ql Prepared quicklogin string * @return array original unencrypted data, in array. [0]=>token, [1]=>expires [, [2]=>url ] */ public function ql_decode($ql) { $out = $ql; $out = Base64::fix_from_url($out); $out = $this->_encrypt->decode($out); $out = explode($this->_config['ql_separator'], $out, 3); return $out; }
/** * Add a file to the Blog * * @param &io.File file * @return array url of the file */ public function newMediaObject($file) { return $this->invoke('metaWeblog.newMediaObject', $this->blogid, $this->username, $this->password, array('name' => $file->getFileName(), 'type' => MimeType::getByFilename($file->getFileName()), 'bits' => Base64::encode(FileUtil::getContents($file)))); }
/** * Creates a random string with the given maximum length * * With the default parameter, the output should contain at least as much randomness as a UUID * * @param int $maxLength the maximum length of the output string (integer multiple of 4) * @return string the new random string */ public static function createRandomString($maxLength = 24) { // calculate how many bytes of randomness we need for the specified string length $bytes = floor(intval($maxLength) / 4) * 3; // get random data $data = openssl_random_pseudo_bytes($bytes); // return the Base64-encoded result return Base64::encode($data, true); }
$maxUploadSize = 1048576; $file = $_FILES['uploadedFile']; $uploadedFile = $file['tmp_name']; $uploadedFileSize = $file['size']; $uploadedExtension = substr($file['name'], -3); $channel = $_GET['c']; $downloadDir = "../../../download/"; if (!$uploadedFileSize || ($channel < 0 || $channel >= MAX_CHANNELS)) { echo "\n <script type='text/javascript'>\n alert('There was an error uploading the sound.');\n </script>"; return; } if ($uploadedFileSize > $maxUploadSize) { echo "\n <script type='text/javascript'>\n alert('File must be no larger than 1MB.');\n </script>"; return; } $base64 = new Base64(); $outStr = "\n <script type='text/javascript'>\n var parentDoc = window.top.document;\n\n function initPlayerControls() {\n parentDoc.getElementById('cmdPlay" . $channel . "').disabled = false;\n parentDoc.getElementById('cmdClear" . $channel . "').disabled = false;\n parentDoc.getElementById('uploadedFile" . $channel . "').style.display='block';\n parentDoc.getElementById('cmdUpload" . $channel . "').style.display='block';\n parentDoc.getElementById('imgLoader" . $channel . "').style.display='none';\n }"; if ($uploadedExtension == 'ogg') { //CREATE MP3 FROM OGG HERE $wavFile = $downloadDir . genFileName() . '.wav'; $mp3File = $downloadDir . genFileName() . '.mp3'; system('ffmpeg -i ' . $uploadedFile . ' ' . $wavFile); system('lame -h ' . $wavFile . ' ' . $mp3File); $outStr .= "\n parentDoc.getElementById('channelOgg" . $channel . "').innerHTML = '" . $base64->encode($uploadedFile) . "';\n parentDoc.getElementById('channelMp3" . $channel . "').innerHTML = '" . $base64->encode($mp3File) . "';\n initPlayerControls();"; unlink($wavFile); unlink($mp3File); } else { if ($uploadedExtension == 'mp3') { //CREATE OGG FROM MP3 $wavFile = $downloadDir . genFileName() . '.wav'; $oggFile = $downloadDir . genFileName() . '.ogg';
public function testDecode() { $this->assertSame(self::$value, $this->defaultEncoding->decode('ZsO4w7hiYXJiYXo')); $this->assertSame(self::$value, $this->nonDefaultEncoding->decode('ZsO4w7hiYXJiYXo=')); }
public function action_unsubscribe() { $email_encoded = $this->request->param('id'); $user = new Model_User(); //mail encoded if ($email_encoded !== NULL) { //decode emails $email_encoded = Base64::fix_from_url($email_encoded); $encrypt = new Encrypt(Core::config('auth.hash_key'), MCRYPT_MODE_NOFB, MCRYPT_RIJNDAEL_128); $email = $encrypt->decode($email_encoded); if (Valid::email($email, TRUE)) { //check we have this email in the DB $user = new Model_User(); $user = $user->where('email', '=', $email)->limit(1)->find(); } else { Alert::set(Alert::INFO, __('Not valid email.')); } } elseif (Auth::instance()->logged_in()) { $user = Auth::instance()->get_user(); } //lets unsubscribe the user if ($user->loaded()) { $user->subscriber = 0; $user->last_modified = Date::unix2mysql(); try { $user->save(); Alert::set(Alert::SUCCESS, __('You have successfuly unsubscribed')); } catch (Exception $e) { //throw 500 throw HTTP_Exception::factory(500, $e->getMessage()); } } else { Alert::set(Alert::INFO, __('Pleae login to unsubscribe.')); } //smart redirect if (Auth::instance()->logged_in()) { $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit'))); } else { $this->redirect(Route::url('default')); } }
/** * Replace the existing long-term authentication cookie * * @param string $token * @param int $userId * @return mixed */ public function rotateToken(string $token, int $userId = 0) { try { $decoded = Base64::decode($token); } catch (\RangeException $ex) { return false; } if ($decoded === false) { return false; } elseif (Binary::safeStrlen($decoded) !== self::LONG_TERM_AUTH_BYTES) { return false; } $sel = Binary::safeSubstr($decoded, 0, self::SELECTOR_BYTES); \Sodium\memzero($decoded); // Delete the old token $this->db->delete($this->tableConfig['table']['longterm'], [$this->tableConfig['fields']['longterm']['selector'] => Base64::encode($sel)]); // Let's get a new token return $this->createAuthToken($userId); }
<?php include 'base64.php'; $bs64 = new Base64(); var_dump($bs64->decode("dGVzdA==")); var_dump($bs64->encode("test"));
// print "Zero byte padded length: " . strlen($zp) . "<br/>\n"; print "Zero byte unpadded length: " . strlen($zup) . "<br/><br/>\n"; /** * Test Base16 (hex) encoding. */ $b16enc = Base16::encode($input); $b16dec = Base16::decode($b16enc); // print "Base16 encoded in UTF-8: " . $b16enc . "<br/>"; print "Base16 decoded in UTF-8: " . $b16dec . "<br/><br/>\n"; /** * Test Base64 encoding. */ $b64enc = Base64::encode($input); $b64dec = Base64::decode($b64enc); // print "Base64 encoded in UTF-8: " . $b64enc . "<br/>"; print "Base64 decoded in UTF-8: " . $b64dec . "<br/><br/>\n"; /** * Test creating GUID's. */ print "Created GUID 1: " . GUID::create() . "<br/>"; print "Created GUID 2: " . GUID::create() . "<br/>"; print "Created GUID 3: " . GUID::create() . "<br/><br/>\n"; /** * Test ROT13 encoding. */ $rot13enc = ROT13::encode($input); $rot13dec = ROT13::decode($rot13enc); //
/** * Create an InternetAddress object from a string * * Recognizes: * <pre> * Timm Friebe <*****@*****.**> * friebe@example.com (Timm Friebe) * "Timm Friebe" <*****@*****.**> * friebe@example.com * <*****@*****.**> * =?iso-8859-1?Q?Timm_Friebe?= <*****@*****.**> * </pre> * * @param string str * @return peer.mail.InternetAddress address object * @throws lang.FormatException in case the string could not be parsed into an address */ public static function fromString($str) { static $matches = array('/^=\\?([^\\?])+\\?([QB])\\?([^\\?]+)\\?= <([^ @]+@[0-9a-z.-]+)>$/i' => 3, '/^<?([^ @]+@[0-9a-z.-]+)>?$/i' => 0, '/^"([^"]+)" <([^ @]+@[0-9a-z.-]+)>$/i' => 2, '/^([^<]+) <([^ @]+@[0-9a-z.-]+)>$/i' => 2, '/^([^ @]+@[0-9a-z.-]+) \\(([^\\)]+)\\)$/i' => 1); $str = trim(chop($str)); foreach ($matches as $match => $def) { if (!preg_match($match, $str, $_)) { continue; } switch ($def) { case 0: $mail = $_[1]; $personal = ''; break; case 1: $mail = $_[1]; $personal = $_[2]; break; case 2: $mail = $_[2]; $personal = $_[1]; break; case 3: $mail = $_[4]; switch (strtoupper($_[2])) { case 'Q': $personal = QuotedPrintable::decode($_[3]); break; case 'B': $personal = Base64::decode($_[3]); break; } break; } break; } // Was it unparsable? if (!isset($mail)) { throw new FormatException('String "' . $str . '" could not be parsed'); } return new InternetAddress($mail, $personal); }
/** * sends an email using our configs * @param string/array $to array(array('name'=>'chema','email'=>'chema@'),) * @param [type] $to_name [description] * @param [type] $subject [description] * @param [type] $body [description] * @param [type] $reply [description] * @param [type] $replyName [description] * @param [type] $file [description] * @return boolean */ public static function send($to, $to_name = '', $subject, $body, $reply, $replyName, $file = NULL) { require_once Kohana::find_file('vendor', 'php-mailer/phpmailer', 'php'); $body = Text::nl2br($body); //get the unsubscribe link $email_encoded = NULL; //is sent to a single user get hash to auto unsubscribe if (!is_array($to) or count($to) == 1) { //from newsletter sent if (isset($to[0]['email'])) { $email_encoded = $to[0]['email']; } else { $email_encoded = $to; } //encodig the email for extra security $encrypt = new Encrypt(Core::config('auth.hash_key'), MCRYPT_MODE_NOFB, MCRYPT_RIJNDAEL_128); $email_encoded = Base64::fix_to_url($encrypt->encode($email_encoded)); } $unsubscribe_link = Route::url('oc-panel', array('controller' => 'auth', 'action' => 'unsubscribe', 'id' => $email_encoded)); //get the template from the html email boilerplate $body = View::factory('email', array('title' => $subject, 'content' => $body, 'unsubscribe_link' => $unsubscribe_link))->render(); //sendign via elasticemail if (Core::config('email.elastic_active') == TRUE) { return self::ElasticEmail($to, $to_name, $subject, $body, core::config('email.notify_email'), "no-reply " . core::config('general.site_name')); } else { $mail = new PHPMailer(); $mail->CharSet = Kohana::$charset; if (core::config('email.smtp_active') == TRUE) { require_once Kohana::find_file('vendor', 'php-mailer/smtp', 'php'); $mail->IsSMTP(); //SMTP HOST config if (core::config('email.smtp_host') != "") { $mail->Host = core::config('email.smtp_host'); // sets custom SMTP server } //SMTP PORT config if (core::config('email.smtp_port') != "") { $mail->Port = core::config('email.smtp_port'); // set a custom SMTP port } //SMTP AUTH config if (core::config('email.smtp_auth') == TRUE) { $mail->SMTPAuth = TRUE; // enable SMTP authentication $mail->Username = core::config('email.smtp_user'); // SMTP username $mail->Password = core::config('email.smtp_pass'); // SMTP password if (core::config('email.smtp_ssl') == TRUE) { $mail->SMTPSecure = "ssl"; // sets the prefix to the server } } } $mail->From = core::config('email.notify_email'); $mail->FromName = "no-reply " . core::config('general.site_name'); $mail->Subject = $subject; $mail->MsgHTML($body); if ($file !== NULL) { $mail->AddAttachment($file['tmp_name'], $file['name']); } $mail->AddReplyTo($reply, $replyName); //they answer here if (is_array($to)) { foreach ($to as $contact) { $mail->AddBCC($contact['email'], $contact['name']); } } else { $mail->AddAddress($to, $to_name); } $mail->IsHTML(TRUE); // send as HTML if (!$mail->Send()) { //to see if we return a message or a value bolean Alert::set(Alert::ALERT, "Mailer Error: " . $mail->ErrorInfo); return FALSE; } else { return TRUE; } } return FALSE; }
$f->Add('S', 5); $f->Add('T', 7); $f->Add('U', 4); $f->Add('V', 2); $f->Add('W', 2); $f->Add('X', 1); $f->Add('Y', 2); $f->Add('Z', 1); $binary = HuffmanStream::GetBinaryStream($f, 'INFORMATIONISTHES'); //echo strlen($binary);exit; //echo '<br>'; $base64 = Base64::Encode($binary); echo $base64; echo '<br>'; $f->Reset(); echo HuffmanStream::GetSymbolStream($f, Base64::Decode($base64)); class HuffmanStream { var $frequency_table; public static function GetBinaryStream($frequencies, $symbol_stream) { $stream = ''; $length = strlen($symbol_stream); for ($index = 0; $index < $length; $index++) { $codes = Huffman::GetCodes($frequencies->AsTable()); $symbol = substr($symbol_stream, $index, 1); $stream .= $codes[$symbol]; $frequencies->Adjust($symbol, -1); } return $stream; }
$plugins[] = $file; } } } closedir($dir); } /** * verify configuration info */ if ($errors == 0) { AddTrace('File Structure....OK!'); if (!mysql_connect($GLOBALS['configuration']['host'] . ":" . $GLOBALS['configuration']['port'], $GLOBALS['configuration']['user'], $GLOBALS['configuration']['pass'])) { $errors++; AddError('Cannot connect to the specified database server. Edit configuration.php'); } if (isset($GLOBALS['configuration']['db_encoding']) && $GLOBALS['configuration']['db_encoding'] == 1 && !Base64::IsBase64FunctionInstalled()) { $errors++; AddError('$configuration[db_encoding] needs to be set to 0 until you install the base64 plugin. Set db_encoding to 0 by editing configuration.php, run setup again and go to the "Manage Plugins" tab. Install the base64 plugin. Then you can set db_encoding = 1'); } if ($errors == 0) { if (!@mysql_select_db($GLOBALS['configuration']['db'])) { $errors++; AddError('Cannot find the specified database "' . $GLOBALS['configuration']['db'] . '". Edit configuration.php'); } } } /** * verify storage status */ if ($errors == 0) { AddTrace("Configuration Info....OK!\n");
public function testEncoding() { $random_bytes = \random_bytes(31); // Backwards compatibility: $encoder = Halite::chooseEncoder(false); $this->assertSame(Hex::encode($random_bytes), $encoder($random_bytes)); $encoder = Halite::chooseEncoder(true); $this->assertSame(null, $encoder); // New encoding in version 3: $encoder = Halite::chooseEncoder(Halite::ENCODE_HEX); $this->assertSame(Hex::encode($random_bytes), $encoder($random_bytes)); $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE32); $this->assertSame(Base32::encode($random_bytes), $encoder($random_bytes)); $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE32HEX); $this->assertSame(Base32Hex::encode($random_bytes), $encoder($random_bytes)); $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE64); $this->assertSame(Base64::encode($random_bytes), $encoder($random_bytes)); $encoder = Halite::chooseEncoder(Halite::ENCODE_BASE64URLSAFE); $this->assertSame(Base64UrlSafe::encode($random_bytes), $encoder($random_bytes)); }