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

Similar posts
  • Computer Security Tips: Stay Safe Onl... In recent times cyber security has raised the level of awareness and public consciousness as never before. Both large corporations and big organizations try to take care of online security as much as they can. That’s why cyber criminals and hackers have focused more on smaller companies and single entrepreneurs. This awful tendency leads to [...]
  • SecurityXploded Mentorship Programme ... I am writing this blog to share my SecurityXploded Student Mentorship Programme experience with the future students of this programme. My mentorship programme started last year in August when I was in 2nd year of MS at IIIT-Allahabad. I knew about SecurityXploded community since I used to follow their blogs, training programmes and security tools [...]
  • Code Injection and API Hooking Techni... Hooking covers a range of techniques used for many purposes like debugging, monitoring, intercepting messages, extending functionality etc. Hooking is also used by a lot of rootkits to camouflage themselves on the system. Rootkits use various hooking techniques when they have to hide a process, hide a network port, redirect file writes to some different [...]
  • Announcement – SecurityXploded ... From the past two years we are working actively on couple of projects to support the security community. As you all may already know that we have successfully completed our reversing and malware analysis training programme and we are very glad that it was very helpful for everyone. In my opinion the success of any [...]
  • Advanced Malware Analysis Training Se... Here is the quick update on this month’s Local Security meet (SX/Null/G4H/owasp) and our advanced malware training session on (Part 2) Dissecting the HeartBeat  RAT Functionalities   This is part of our FREE ‘Advanced Malware Analysis Training’ series started from Dec 2012.       In this extended session, I explained “Decrypting various Communications Of HeartBeat [...]

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