Core Function UUEncode

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> UUEncode( <expression> ) </pre> === Description === Encodes a string using the uuencode algorithm. Uuencode translates all strings (including binary's ones) into printa...")
 
m (1 revision)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
UUEncode( <expression> )
+
UUEncode( <expression> )
 
</pre>
 
</pre>
  
Line 36: Line 36:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
echo UUEncode("Testy");
+
my $Encoded = UUEncode("Testy");
# Prints:
+
echo "Encoded: $Encoded\n";
# %5&5S='D`
+
my $Decoded = UUDecode($Encoded);
 +
echo "Decoded: $Decoded\n";
 +
# Prints
 +
# Encoded: %5&5S='D`
 
# `
 
# `
 +
#
 +
# Decoded: Testy
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Perl compatible UUEncode a string
 
Perl compatible UUEncode a string
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
echo PerlUUEncode("Testy");
+
my $Encoded = PerlUUEncode("Testy");
# Prints: %5&5S='D`
+
echo "Encoded: $Encoded\n";
 +
my $Decoded = PerlUUDecode($Encoded);
 +
echo "Decoded: $Decoded\n";
 +
# Prints
 +
# Encoded: %5&5S='D`
 +
#
 +
# Decoded: Testy
  
 
Function PerlUUEncode ( $str )
 
Function PerlUUEncode ( $str )
 
{
 
{
 
return (string)pack("u", $str);
 
return (string)pack("u", $str);
 +
}
 +
 +
Function PerlUUDecode ( $str )
 +
{
 +
return unpack("u", $str, 3);
 
}
 
}
  
Line 56: Line 72:
 
# valid and Unpack() will read both the Perl/PHP styles
 
# valid and Unpack() will read both the Perl/PHP styles
 
# with no problem
 
# 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
 +
</syntaxhighlight>
 +
 +
Using Unicode
 +
 +
<syntaxhighlight lang="sputnik">
 +
$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);
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

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