這是我自己改的,但結果不對.全是0000000
<?php
function  JiaMie($s) //Encrypt
{
  
  for ($i=1;$i<=strlen($s);$i++)
  {
    $c=substr($s,$i,1);
    $h=($c >> 4 ) & (0xf); // High 4 Bit
    $l=$c & 0xf; // Low 4 Bit
    $j=$j.('a'+$h).('a'+l);
  }
  return($j);
}/*
function JieMie(String s) //

  String j="";
  for (int i=1;i<=s.Length();i=i+2)
  {
    int h=(s[i]-'a');
    int l=(s[i+1]-'a');
    char c=(h<<4)+(l&0xf);
    j=j+c;
  }
  return(j);
}
*/
echo JiaMie('1111');?>

解决方案 »

  1.   

    $j=$j.('a'+$h).('a'+l);
      =>  $j=$j.('a'+$h).('a'+$l); 先改了试试,我还有别的疑问
      

  2.   

    :)
    $c=substr($s,$i,1);
        $h=($c >> 4 ) & (0xf); // High 4 Bit
    從這裡輸出都為0了
      

  3.   

    $c 改为 ord($c) 即可
      

  4.   

    function  JiaMie($s) //Encrypt
    {
      
      for ($i=1;$i<=strlen($s);$i++)
      {
        $c=substr($s,$i,1);
        $h=(ord($c) >> 4 ) & (0xf); // High 4 Bit
        $l=ord($c) & 0xf; // Low 4 Bit
        $j=$j.('a'+$h).('a'+$l);
      }
      return($j);
    }改了也不行哦
    正常的話
    在C裡函數
    JiaMie("1234")="dbdcddde"
    但現在 在PHP裡
    JiaMie("1234")="32333400"
      

  5.   

    function  JiaMie($s) //Encrypt
    {
      
      for ($i=0;$i<strlen($s);$i++)
      {
        $c=substr($s,$i,1);
        $h=(ord($c) >> 4 ) & (0xf); // High 4 Bit
        $l=ord($c) & 0x0f; // Low 4 Bit
        $j=$j.chr(ord('a')+$h).chr(ord('a')+$l);
      }
      return($j);
    }