summaryrefslogtreecommitdiff
path: root/PHP4
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2024-12-10 21:28:04 +0900
committerhaturatu <taro@eyes4you.org>2024-12-10 21:28:04 +0900
commitfe6c36e18042603bb096d3685fe3988e32331ebf (patch)
tree359c42bed67e5eee7342b2e95810dfe501c69665 /PHP4
first commitHEADmain
Diffstat (limited to 'PHP4')
-rw-r--r--PHP4/README40
-rw-r--r--PHP4/base91.php71
2 files changed, 111 insertions, 0 deletions
diff --git a/PHP4/README b/PHP4/README
new file mode 100644
index 0000000..b357bad
--- /dev/null
+++ b/PHP4/README
@@ -0,0 +1,40 @@
+base91_encode -- Encodes data with basE91
+
+ string base91_encode ( string data )
+
+base91_encode() returns data encoded with basE91. This encoding is designed to
+make binary data survive transport through transport layers that are not 8-bit
+clean, such as mail bodies.
+
+basE91-encoded data takes at most 23% more space than the original data.
+
+Example:
+<?php
+ require_once 'base91.php';
+ $str = 'This is an encoded string';
+ echo base91_encode($str);
+?>
+
+This example will produce:
+
+nX,<:WRT%yV%!5:maref3+1RrUb64^M
+
+-----
+
+base91_decode -- Decodes data encoded with basE91
+
+ string base91_decode ( string encoded_data )
+
+base91_decode() decodes encoded_data ignoring non-alphabet characters and
+returns the original data. The returned data may be binary.
+
+Example:
+<?php
+ require_once 'base91.php';
+ $str = 'nX,<:WRT%yV%!5:maref3+1RrUb64^M';
+ echo base91_decode($str);
+?>
+
+This example will produce:
+
+This is an encoded string
diff --git a/PHP4/base91.php b/PHP4/base91.php
new file mode 100644
index 0000000..ea34f03
--- /dev/null
+++ b/PHP4/base91.php
@@ -0,0 +1,71 @@
+<?php
+// Copyright (c) 2005-2006 Joachim Henke
+// http://base91.sourceforge.net/
+
+$b91_enctab = array(
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$',
+ '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
+ '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'
+);
+$b91_dectab = array_flip($b91_enctab);
+
+function base91_decode($d)
+{
+ global $b91_dectab;
+ $l = strlen($d);
+ $v = -1;
+ for ($i = 0; $i < $l; ++$i) {
+ $c = $b91_dectab[$d{$i}];
+ if (!isset($c))
+ continue;
+ if ($v < 0)
+ $v = $c;
+ else {
+ $v += $c * 91;
+ $b |= $v << $n;
+ $n += ($v & 8191) > 88 ? 13 : 14;
+ do {
+ $o .= chr($b & 255);
+ $b >>= 8;
+ $n -= 8;
+ } while ($n > 7);
+ $v = -1;
+ }
+ }
+ if ($v + 1)
+ $o .= chr(($b | $v << $n) & 255);
+ return $o;
+}
+
+function base91_encode($d)
+{
+ global $b91_enctab;
+ $l = strlen($d);
+ for ($i = 0; $i < $l; ++$i) {
+ $b |= ord($d{$i}) << $n;
+ $n += 8;
+ if ($n > 13) {
+ $v = $b & 8191;
+ if ($v > 88) {
+ $b >>= 13;
+ $n -= 13;
+ } else {
+ $v = $b & 16383;
+ $b >>= 14;
+ $n -= 14;
+ }
+ $o .= $b91_enctab[$v % 91] . $b91_enctab[$v / 91];
+ }
+ }
+ if ($n) {
+ $o .= $b91_enctab[$b % 91];
+ if ($n > 7 || $b > 90)
+ $o .= $b91_enctab[$b / 91];
+ }
+ return $o;
+}
+?>