4

PHPでこのVigenere cypherを修正するのを手伝ってくれる人はいますか?

引き裂かれたコードで申し訳ありません。それは私が何時間も分析してきたところからです-修正しようとしています!

とにかく、コードは「Abc」を出力すべきときに「Ace」を出力します。

修正する数学の頭脳を持っていない奇妙な二重オフセットがあります! 読んでくれてありがとう。

コードは AutoHotkey スクリプトのhereからのものです- 私はそれを転写しようとしました。Web には PHP Vigenere の例があります ( Rosetta Codeにはありませんが、奇妙なことに!).. しかし、とにかく、これは標準の大文字だけでなく小文字も受け入れるように変更されています。ありがとう。

  $key = "AAA";
  $keyLength = 3;
  $keyIndex = 0;
  $messageAsArray[0] = "A";
  $messageAsArray[1] = "b";
  $messageAsArray[2] = "c";

  foreach ($messageAsArray as $value)    //Loop through input string array
  {  
      $thisValueASCII = ord($value);
      if ($thisValueASCII >= 65 && $thisValueASCII <= 90) //if is uppercase                                  
      { 
        $thisValueASCIIOffset = 65; 
      }
      else //if is lowercase
      {
        $thisValueASCIIOffset = 97;  
      }
      $thisA = $thisValueASCII - $thisValueASCIIOffset;
      $thisB = fmod($keyIndex,$keyLength);
      $thisC = substr($key, $thisB, 1);
      $thisD = ord($thisC) - 65;
      $thisE = $thisA + $thisD;
      $thisF = fmod($thisE,26);
      $thisG = $thisF + $thisValueASCII  ;
      $thisOutput = chr($thisG); 
      $output = $output . $thisOutput  ; 
      $keyIndex++;
  }
  echo $output
4

1 に答える 1