PHP Classes
Icontem

File: example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Rubens Takiguti Ribeiro  >  ASCII85 - binary to text  >  example.php  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of use
Class: ASCII85 - binary to text
Encoding and decoding data in ASCII85 encoding
 

Contents

Class file image Download
<?php
// Some examples of class usage
require_once(dirname(__FILE__).'/ascii85.class.php');


$text 'A text with many zero-bytes ('.str_repeat(chr(0), 10).') and many spaces ('.str_repeat(' '10).') end.';

// Encode using DEFAULT algorithm
$basic_encoded ascii85::encode($textascii85::BASIC72);
try {
    
$basic_decoded ascii85::decode($basic_encoded);
catch (Exception $e) {
    
$basic_decoded 'Error '.$e->getCode().': '.$e->getMessage();
}

// Encode using ADOBE variation
$adobe_encoded ascii85::encode($textascii85::ADOBE72);
try {
    
$adobe_decoded ascii85::decode($adobe_encodedascii85::ADOBE);
catch (Exception $e) {
    
$adobe_decoded 'Error '.$e->getCode().': '.$e->getMessage();
}


// Encode using BTOA variation
$btoa_encoded ascii85::encode($textascii85::BTOA72);
try {
    
$btoa_decoded ascii85::decode($btoa_encodedascii85::BTOA);
catch (Exception $e) {
    
$btoa_decoded 'Error '.$e->getCode().': '.$e->getMessage();
}

// Format ant print result
$text          htmlentities($text,          ENT_COMPAT'UTF-8');
$basic_encoded htmlentities($basic_encodedENT_COMPAT'UTF-8');
$basic_decoded htmlentities($basic_decodedENT_COMPAT'UTF-8');
$adobe_encoded htmlentities($adobe_encodedENT_COMPAT'UTF-8');
$adobe_decoded htmlentities($adobe_decodedENT_COMPAT'UTF-8');
$btoa_encoded  htmlentities($btoa_encoded,  ENT_COMPAT'UTF-8');
$btoa_decoded  htmlentities($btoa_decoded,  ENT_COMPAT'UTF-8');

header('Content-type: text/html; charset=UTF-8');
echo <<<HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Example of ASCII85 Class usage</title>
<style type="text/css" rel="stylesheet"><!--
pre 
{ border: 1px solid #000000; background-color: #FFFFFF; padding: .5em; }
h2 
{ margin: 0; }
div 
{ padding: 1em; margin-bottom: .2em; }
.basic 
{ border: 1px outset #EEEEFF; background-color: #EEEEFF; }
.adobe 
{ border: 1px outset #EEFFEE; background-color: #EEFFEE; }
.btoa 
{ border: 1px outset #FFEEEE; background-color: #FFEEEE; }
--></style>
</head>
<body>

<h1>Example of Ascii85 Class usage</h1>
<p>Original text:<br /><pre>
{$text}</pre></p>

<div class="basic">
<h2>Basic</h2>
<p>Definition: this algorithm convert a binary sequence to a text sequence using 
   basicaly 85 characters. The idea is to represent a tuple of four bytes as
   a tuple of five printable characters.</p>
<p>Encoded:<br /><pre>
{$basic_encoded}</pre></p>
<p>Decoded:<br /><pre>
{$basic_decoded}</pre></p>
</div>

<div class="adobe">
<h2>Adobe Variant</h2>
<p>Diferences: this variant is delimited by &lt;~ and ~&gt;.
   It uses "z" character to represent a tuple with four
   zero-byte (0x00).</p>
<p>Encoded:<br /><pre>
{$adobe_encoded}</pre></p>
<p>Decoded:<br /><pre>
{$adobe_decoded}</pre></p>
</div>

<div class="btoa">
<h2>BTOA Variant</h2>
<p>Diferences: this variant is delimited by "xbtoa Begin" and "xbtoa End".
   It includes some verification data (text length, check XOR, check SUM and check ROT).
   It uses "z" character to represent a tuple with four zero-byte (0x00) and
   "y" character to represent a tuple with four white-space (0x22).</p>
<p>Encoded:<br /><pre>
{$btoa_encoded}</pre></p>
<p>Decoded:<br /><pre>
{$btoa_decoded}</pre></p>
</div>

</body>
</html>
HTML;

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products