Translation of line from c# to php



  •   byte[] hashedData = hmacGenerator.ComputeHash(tarrrr);
            byte[] codeArray = new byte[5];
            try
            {
                byte b = (byte)(hashedData[19] & 0xF);
                int Point = (hashedData[b] & 0x7F) << 24 | (hashedData[b + 1] & 0xFF) << 16 | (hashedData[b + 2] & 0xFF) << 8 | (hashedData[b + 3] & 0xFF);
    
                for (int i = 0; i < 5; ++i)
                {
                    codeArray[i] = CodeTranslations[Point % CodeTranslations.Length];
                    Point /= CodeTranslations.Length;
                }
            }
    

    I'm really interested in how this line looks at the PHP.

    Original at C#



  • Based on the assumption that yours is hmacGenerator It's a SHA1 hesh (in 20-bite length) and it's like:

      $hashedData=sha1($tarrrr,true);
      $b=ord($hashedData[19]) & 0xF;
      $Point=unpack("N",substr($hashedData,$b,4))[1] & 0x7FFFFFFF;
    

    $arrLen=count($CodeTranslations);
    $codeArray="";
    for ($i = 0; $i < 5; $i++):
    $codeArray .= chr($CodeTranslations[$Point % $arrLen]);
    $Point = (int)($Point/$arrLen);
    endfor;




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2