?
Solved

PHP: Binary Safe  Base36 Encoding / Decoding

Posted on 2010-11-09
1
Medium Priority
?
727 Views
Last Modified: 2012-05-10
I want to be able to convert a string of text or binary data into a series of numbers and lowercase letters.

This should work in a way similar to base64_encode() however only numbers and lowercase letters should be used.

My function works with numbers but not with text or binary data.

<?php

echo base36_encode('555555555');
echo '<hr />';
echo base36_encode('Hello World, this is a test!');

function base36_encode($base10){
    return base_convert($base10,10,36);
}
 
function base36_decode($base36){
    return base_convert($base36,36,10);
}

?>

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 total points
ID: 34097527
Base64 encoding uses 6 bits ( 2**6  = 64 ) to package data. So if you take (say) 3 characters at 8 bits each that is 24 bits and is equivalent to four sets of 6 bits. Thus if you envisage the data as being laid as a stream of bits and picked up in groups of 6 then you get the idea (this is more how uuencode worked but you get the idea)

So your problem with base 36 is that 36 is 2**5.17 which will never do. You could use base 32 which is exactly five bits and then group your data into 40 bit groups (5 eight-bit bytes == 8 five bit groups) then you would be in business, so to speak.

The real problem here is getting the data to map into consistent groups and patterns so that you can use bit shifting and masking to pull out the data streams

0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question