Core Function UUDecode

From Sputnik Wiki
Jump to: navigation, search
UUDecode( <expression> )

Contents

Description

Decodes a string that was encode using the uuencode algorithm .

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