Yahoo64 – Secret Encoding Algorithm of Yahoo

Yahoo has always given promising security for its applications such as Yahoo Messenger, clearly evident from its Secure Authentication protocol and the fact that only Messenger whose password is not possible to decrypt directly (starting from version 7.0). Yahoo has consistently improved the security around the Yahoo Messenger over the time such as clearing in-memory password, better authentication protocol, storing encrypted password token instead of password etc.
.

It has always used its own algorithms and protocols which are generally derived from the standard ones. One such algorithm is Yahoo64 – customized version of popular BASE64 encoding/decoding algorithm.
.

.
Like BASE64, Yahoo Messenger uses Yahoo64 algorithm for storing or transferring the sensitive binary data in ASCII format. If you have read our post on password secrets of Yahoo Messenger, it will be clear how Yahoo Messenger stores its encrypted password token in registry after encoding it with Yahoo64. It also uses the same encoding mechanism while transferring the sensitive authentication tokens over the wire.

.

Yahoo64 encoding/decoding algorithm is very similar to BASE64. It differs mainly in its character set, padding character and slight deviation within the main algorithm.

.
Here’s the BASE64 character set
“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/”

.
and this one is used by Yahoo64
“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._”

.

Here’s the complete encoding and decoding algorithm for Yahoo64

.

//
// Credits : Slick [slick@rstzone.org]
//
function yahoo64_encode($source)
{
  $yahoo64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
  $limit=strlen($source)-(strlen($source)%3);
  $dest=""; 

  for($i=0;$i<$limit;$i+=3)
  {
    $dest.=$yahoo64[ord($source[$i])>>2];
    $dest.=$yahoo64[((ord($source[$i])<<4)&0x30) | (ord($source[$i+1])>>4)];
    $dest.=$yahoo64[((ord($source[$i+1])<<2)&0x3C) | (ord($source[$i+2])>>6)];
    $dest.=$yahoo64[ord($source[$i+2])&0x3F];
  } 

  switch(strlen($source)-$limit)
  {
    case 1:
    {
      $dest.=$yahoo64[ord($source[$i])>>2];
      $dest.=$yahoo64[(ord($source[$i])<<4)&0x30];
      $dest.='--';
    }
    break;     

     case 2:
     {
      $dest.=$yahoo64[ord($source[$i])>>2];
      $dest.=$yahoo64[((ord($source[$i])<<4)&0x30) | (ord($source[$i+1])>>4)];
      $dest.=$yahoo64[((ord($source[$i+1])<<2)&0x3c)];
      $dest.='-';
     }
     break;
  } 

  return($dest); 

} 

function Index($string,$chr)
{
  for($i=0;$i<64;$i++)
  {
    if($string[$i]==$chr) { return($i); }
  } 

  return(-1);
}
 

function yahoo64_decode($source)
{
$yahoo64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
$len=strlen($source);   

if($source[$len-1]=='-') { $plus=2; }    

if($source[$len-2]=='-') { $plus=1; }    

if($plus>0) { $len-=4; }; 

  $dest=""; 

  for($i=0;$i<$len;$i+=4)
  {
    $chr1=Index($yahoo64,$source[$i]);
    $chr2=Index($yahoo64,$source[$i+1]);
    $chr3=Index($yahoo64,$source[$i+2]);
    $chr4=Index($yahoo64,$source[$i+3]);

    $dest.=chr(($chr1<<2)|($chr2>>4));
    $dest.=chr((($chr2&0xF)<<4)|($chr3>>2));
    $dest.=chr((($chr3&0x3)<<6)|($chr4&0x3F));
  } 

  switch($plus)
  {
    case 1:
    {
      $chr1=Index($yahoo64,$source[$i]);
      $chr2=Index($yahoo64,$source[$i+1]);
      $dest.=chr(($chr1<<2)|($chr2>>4));
    }
    break; 

    case 2:
    {
      $chr1=Index($yahoo64,$source[$i]);
      $chr2=Index($yahoo64,$source[$i+1]);
      $chr3=Index($yahoo64,$source[$i+2]);
      $dest.=chr(($chr1<<2)|($chr2>>4));
      $dest.=chr((($chr2&0xF)<<4)|($chr3>>2));
    }
    break;
  } 

  return($dest); 

}

.

If you are more interested in knowing Yahoo’s authentication and password storage mechanism read Slick’s research paper In-Depth Analysis of Yahoo! Authentication Schemes”. Above Yahoo64 algorithm is result of his great piece of research work.

.

See Also

CryptoCode: Index of All Crypto Articles

CryptoCode: BASE64 Decoder

Password Secrets of Yahoo Messenger

Yahoo Password Decryptor : Yahoo Password Recovery Tool

No Comments Yet

Leave a Reply

Our Company

Follow us on Facebook


Join Mailing List

Get direct access to our expert trainers or mingle with like minded security folks in our mailing list