Core Function UUEncode

From Sputnik Wiki
Revision as of 12:37, 14 June 2015 by UberFoX (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
UUEncode( <expression> )

Contents

Description

Encodes a string using the uuencode algorithm.

Uuencode translates all strings (including binary's ones) into printable characters, making them safe for network transmissions.

Uuencoded data is about 35% larger than the original.

Parameters

expression

The data to be encoded.

Can be a string or binary variable.

If it is neither of the above it will be converted into a string and used anyway.

Return Value

Success: Returns the uuencoded data

Failure: Returns empty string.

Remarks

This function produces results that are equal to PHPs.

If you require results equal to Perl try the UUEncode found on the Pack( ) function.

Example

my $Encoded = UUEncode("Testy");
echo "Encoded: $Encoded\n";
my $Decoded = UUDecode($Encoded);
echo "Decoded: $Decoded\n";
# Prints
# Encoded: %5&5S='D`
# `
# 
# Decoded: Testy

Perl compatible UUEncode a string

my $Encoded = PerlUUEncode("Testy");
echo "Encoded: $Encoded\n";
my $Decoded = PerlUUDecode($Encoded);
echo "Decoded: $Decoded\n";
# Prints
# Encoded: %5&5S='D`
# 
# Decoded: Testy
 
Function PerlUUEncode ( $str )
{
	return (string)pack("u", $str);
}
 
Function PerlUUDecode ( $str )
{
	return unpack("u", $str, 3);
}
 
# Notice this Perl compatible one produces a slightly
# different text to the one above? Of course both are
# valid and Unpack() will read both the Perl/PHP styles
# with no problem
 
# Here we see unpack() can decode PHP uuencoded strings
$PHPEncoded = UUEncode("Testy");
my $DecodedPHP = PerlUUDecode($PHPEncoded);
echo "Decoded PHP: $DecodedPHP\n";
# Prints: Decoded PHP: Testy
 
# Here we see UUDecode() can handle Perl encoded ones
$PerlEncoded = PerlUUEncode("Testy");
my $DecodedPerl = UUDecode($PerlEncoded);
echo "Decoded Perl: $DecodedPerl\n";
# Prints: Decoded Perl: Testy

Using Unicode

$Str = "Testy ehehe XD!こんにちは";
$PerlEncoded = PerlUUEncode($Str);
$PHPEncoded = UUEncode($Str);
echo "Encoded Perl: $PerlEncoded\n";
echo "Encoded PHP: $PHPEncoded\n";
my $DecodedPerl = PerlUUDecode($PerlEncoded);
echo "Decoded Perl: $DecodedPerl\n";
msgbox $DecodedPerl;
 
Function PerlUUEncode ( $str )
{
	return (string)pack("u", $str);
}
 
Function PerlUUDecode ( $str )
{
	return unpack("u", $str, 3);
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox