Well, there's ROT13 🙂
The reason why Base64 or uuencoding results in longer strings than the original data is because both are designed to pack arbitrary 8-bit bytes into (a subset of) the 7-bit ASCII character set. Obviously, if you don't want to throw away information, you need more 7-bit ASCII characters than you need 8-bit bytes. And if you want it to be reversible, you don't want to throw away data.
If you're only sending ASCII, as you said, then this isn't an issue - 7-bit ASCII fits in 7-bit ASCII just fine 🙂.
ROT13 is an example - that's easy enough:
$rot13string=strtr($string,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM);
But it only does letters. However, it does suggest one approach.
Another (if you can stand one extra character) might be to whip up a quick XOR. This is really tacky, and I wouldn't suggest it except it's so idiotically simple:
[again, the source string is $string]
srand(time()); // Could be better.
$ord=rand(32,127);
$char=chr($ord); // Pick an ASCII character (ignore those control chars at the bottom)
$newstring=$char;
for($i=0;$i<strlen($string);$i++)
{
$newstring.=chr($ordord($string[$i]));
}
To decrypt:
$char=$newstring[0];
$ord=ord($char);
$string='';
for($i=1;$i<strlen($string);$i++)
{
$string.=chr($ordord($newstring[$i]));
}
Like I say - idiotically simple - the decrypt key is right there at the start of the string!
In the end it's really all a matter of how sensitive you want stuff to be: you can install the mcrypt library and use that; you can try and figure out some methind that avoids having to send the information around at all; or whatever.