Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for yenc encoded overviews. #10

Open
robinvdvleuten opened this issue Jul 31, 2014 · 2 comments
Open

Add support for yenc encoded overviews. #10

robinvdvleuten opened this issue Jul 31, 2014 · 2 comments
Milestone

Comments

@robinvdvleuten
Copy link
Owner

Add support for yenc encoded overviews

@robinvdvleuten robinvdvleuten added this to the 1.0.0 milestone Jul 31, 2014
@kissifrot
Copy link
Contributor

kissifrot commented Oct 12, 2016

The following (basic) code works:

$yEncodedString = 'ybegin**** (yencoded string ******)';

$encoded = array();

// Extract the yEnc string itself.
preg_match("/^(=ybegin.*=yend[^$]*)$/ims", $yEncodedString, $encoded);
if (!isset($encoded[1])) {
    return false;
}

$encoded = $encoded[1];
// Remove the header and trailer from the string before parsing it.
$encoded = preg_replace("/(^=ybegin.*\\r\\n)/im", "", $encoded, 1);
$encoded = preg_replace("/(^=ypart.*\\r\\n)/im", "", $encoded, 1);
$encoded = preg_replace("/(^=yend.*)/im", "", $encoded, 1);

// Remove linebreaks from the string.
$encoded = trim(str_replace("\r\n", "", $encoded));
// Decode
$decoded = '';
for( $i = 0; $i < strlen($encoded); $i++)
{
    if ($encoded{$i} == "=")
    {
        $i++;
        $decoded .= chr((ord($encoded{$i}) - 64) - 42);
    }
    else
    {
        $decoded .= chr(ord($encoded{$i}) - 42);
    }
}

// Do something with the $decoded

@robinvdvleuten
Copy link
Owner Author

@kissifrot can you create a PR for this functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants