需要在PHP中复制解决simples验证码的Ruby函数

需要在PHP中复制解决simples验证码的Ruby函数,php,ruby-on-rails,ruby,Php,Ruby On Rails,Ruby,我正在将一些较旧的代码从ruby翻译成php,其中ruby中有一段代码用于解决验证码图像(验证码图像示例:) 问题是我根本不知道如何开始解决这个问题,因为我对Ruby不太了解。如果您能提供一些帮助,我将不胜感激。我会尝试一下,我已经为您留下了一些工作,让您进行研究,但这至少会让您走上正轨:) 我解决了,我就是这么做的。感谢D Lowther指导我使用正确的函数 preg_match_all('/(?:.*?)id=(.*?)\Z/isu',$captchaUrlAdd, $output);

我正在将一些较旧的代码从ruby翻译成php,其中ruby中有一段代码用于解决验证码图像(验证码图像示例:)


问题是我根本不知道如何开始解决这个问题,因为我对Ruby不太了解。如果您能提供一些帮助,我将不胜感激。

我会尝试一下,我已经为您留下了一些工作,让您进行研究,但这至少会让您走上正轨:)


我解决了,我就是这么做的。感谢D Lowther指导我使用正确的函数

preg_match_all('/(?:.*?)id=(.*?)\Z/isu',$captchaUrlAdd, $output);
    $target = $output[1][0];
    $target = base64_decode($target);
    $target = unserialize($target);
    $target = $target['cryptText'];
    $target = unpack('C*', $target);
    $target = array_values($target);

    $mappingArray = [hexdec('0x51'), hexdec('0xac'), hexdec('0x6d'), hexdec('0x33'), hexdec('0x12')];

    $targetByteArray = array();
    foreach ([$target, $mappingArray] as $row => $columns) {
        foreach ($columns as $row2 => $column2) {
            $targetByteArray[$row2][$row] = $column2;
        }
    }
    $targetEndArray = array();
    foreach ($targetByteArray as $arr) {
        $targetEndArray[] = $arr[0] ^ $arr[1];
    }

    $stringFinal = '';
    foreach ($targetEndArray as $end) {
        $stringFinal .=pack('C*', $end);
    }

谢谢,这正是我想要的。看了一会儿,我发现它是在转换图像的id参数,而不是图像。再次感谢这些函数,因为我对ruby不是很熟悉
function exterminator_captchas($page)
{
  $captcha = unserialize(
    base64_decode(
      preg_replace('/.*?id=/', '', (string)$page['images'][14])
    )
  );

  // This next bit is a bit of pseudo-code I think you'd need to 
  // play with unpack to get the bytestreams.
  $map = [
    /*some unpacking method*/($captcha),
    [0x51, 0xac, 0x6d, 0x33, 0x12],
  ];
  // http://ruby-doc.org/core-2.4.0/Array.html#method-i-transpose
  // would need to look for the right array manipulating method to match.
  $transpose = /* some method */($map);

  return pack('C*', array_map(
    function(pair) {
      return ($pair[0]^$pair[1]);
    }, 
    $transpose
  ));
}
preg_match_all('/(?:.*?)id=(.*?)\Z/isu',$captchaUrlAdd, $output);
    $target = $output[1][0];
    $target = base64_decode($target);
    $target = unserialize($target);
    $target = $target['cryptText'];
    $target = unpack('C*', $target);
    $target = array_values($target);

    $mappingArray = [hexdec('0x51'), hexdec('0xac'), hexdec('0x6d'), hexdec('0x33'), hexdec('0x12')];

    $targetByteArray = array();
    foreach ([$target, $mappingArray] as $row => $columns) {
        foreach ($columns as $row2 => $column2) {
            $targetByteArray[$row2][$row] = $column2;
        }
    }
    $targetEndArray = array();
    foreach ($targetByteArray as $arr) {
        $targetEndArray[] = $arr[0] ^ $arr[1];
    }

    $stringFinal = '';
    foreach ($targetEndArray as $end) {
        $stringFinal .=pack('C*', $end);
    }