<commit_before><?php 
	// nxtlib-php
	// created by <NAME>
	// MIT licenced, use how you'd like (:

	class Nxtlib
	{
		public $nodeAddress;
        public $curve;
        public $convert;
		function __construct($nodeAddr)
		{
			$this->nodeAddress = $nodeAddr;
            $this->curve = new Curve25519();
            $this->convert = new Converters();
		}

		function request($requestType, $params)
		{
			$reqString = "http://".$nodeAddress.":7876/nxt?requestType=".$requestType."&".http_build_query($params);
			$rawtext = file_get_contents($reqString);
			return json_decode($rawtext);
		}



function sign($message, $secretPhrase) {
        $messageBytes = $this->convert->stringToByteArray($message);
        $secretPhraseBytes = $this->convert->stringToByteArray($secretPhrase);

        $digest = $this->convert->hexStringToByteArray(hash("sha256", $secretPhrase));

        $s = $this->curve->keygen($digest)->s;

        $m = $this->convert->hexStringToByteArray(hash("sha256", hex2bin($this->convert->byteArrayToHexString($messageBytes))));

        $x = $this->convert->hexStringToByteArray(hash("sha256", hex2bin($this->convert->byteArrayToHexString(array_merge($m, $s)))));

        $key = $this->curve->keygen($x);
        $x = $key->k;
        $y = $key->p;

        $h = $this->convert->hexStringToByteArray(hash("sha256", hex2bin($this->convert->byteArrayToHexString(array_merge($m, $y)))));

        $v = $this->curve->sign($h, $x, $s);

        return $this->convert->byteArrayToHexString(array_merge($v, $h));
    }



    function verifyBytes(signature, message, publicKey) {
        var signatureBytes = signature;
        var messageBytes = message;
        var publicKeyBytes = publicKey;
        var v = signatureBytes.slice(0, 32);
        var h = signatureBytes.slice(32);
        var y = curve25519.verify(v, h, publicKeyBytes);

        var m = simpleHash(messageBytes);

        _hash.init();
        _hash.update(m);
        _hash.update(y);
        var h2 = _hash.getBytes();

        return areByteArraysEqual(h, h2);
    }


}

class Converters {

public function charToNibble($char)
{
    switch($char)
    {
        case "0": return 0;
        case "1": return 1;
        case "2": return 2;
        case "3": return 3;
        case "4": return 4;
        case "5": return 5;
        case "6": return 6;
        case "7": return 7;
        case "8": return 8;
        case "9": return 9;
        case "a": return 10;
        case "A": return 10;
        case "b": return 11;
        case "B": return 11;
        case "c": return 12;
        case "C": return 12;
        case "d": return 13;
        case "D": return 13;
        case "e": return 14;
        case "E": return 14;
        case "f": return 15;
        case "F": return 15;
    }
    return 0;
}


function hexStringToByteArray($str) {

            $bytes = array();
            $i = 0;
            if (0 !== strlen($str) % 2) {
                array_push($bytes, $this->charToNibble($str[0]));
                ++$i;
            }

            for (; $i < strlen($str) - 1; $i += 2) {
                array_push($bytes, ($this->charToNibble($str[$i]) << 4) + $this->charToNibble($str[$i + 1]));

            }

            return $bytes;
}

function byteArrayToHexString($bytes) {
    $nibbleToChar = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];

            $str = '';
            for ($i = 0; $i < count($bytes); ++$i) {
                if ($bytes[$i] < 0) {
                    $bytes[$i] += 256;
                }
                $str .= $nibbleToChar[$bytes[$i] >> 4] . $nibbleToChar[$bytes[$i] & 0x0F];
            }

            return $str;
        }

        function stringToByteArray($str) {
            //str = unescape(encodeURIComponent(str)); //temporary

            $bytes = array_pad(array(), strlen($str), 0);
            for ($i = 0; $i < strlen($str); ++$i)
                $bytes[$i] = ord($str[$i]);

            return $bytes;
        }

 function areByteArraysEqual($bytes1, $bytes2) {
        if (count($bytes1) !== count($bytes2))
            return false;

        for (var i = 0; i < bytes1.length; ++i) {
            if (bytes1[i] !== bytes2[i])
                return false;
        }

        return true;
    }


}



    /* Ported to PHP from Javascript by <NAME> 1/29/15
 * Ported to JavaScript from Java 07/01/14.
 *
 * Ported from C to Java by <NAME> [sahn0], 23/02/08.
 * Original: http://cds.xs4all.nl:8081/ecdh/
 */
/* Generic 64-bit integer implementation of Curve25519 ECDH
 * Written by <NAME>, 200608242056
 * Public domain.
 *
 * Based on work by <NAME>, http://cr.yp.to/ecdh.html
 */

class Curve25519 {
<commit_msg>public and private key gen<commit_after><?php 
	// nxtlib-php
	// created by <NAME>
	// MIT licenced, use how you'd like (:

	class Nxtlib
	{
		public $nodeAddress;
        public $curve;
        public $convert;
		function __construct($nodeAddr)
		{
			$this->nodeAddress = $nodeAddr;
            $this->curve = new Curve25519();
            $this->convert = new Converters();
		}

		function request($requestType, $params)
		{
			$reqString = "http://".$nodeAddress.":7876/nxt?requestType=".$requestType."&".http_build_query($params);
			$rawtext = file_get_contents($reqString);
			return json_decode($rawtext);
		}



        function signBytes($message, $secretPhrase) {
            $messageBytes = $message;
            $secretPhraseBytes = $this->convert->stringToByteArray($secretPhrase);

            $digest = $this->convert->hexStringToByteArray(hash("sha256", $secretPhrase));

            $s = $this->curve->keygen($digest)->s;

            $m = $this->convert->hexStringToByteArray(hash("sha256", hex2bin($this->convert->byteArrayToHexString($messageBytes))));

            $x = $this->convert->hexStringToByteArray(hash("sha256", hex2bin($this->convert->byteArrayToHexString(array_merge($m, $s)))));

            $key = $this->curve->keygen($x);
            $x = $key->k;
            $y = $key->p;

            $h = $this->convert->hexStringToByteArray(hash("sha256", hex2bin($this->convert->byteArrayToHexString(array_merge($m, $y)))));

            $v = $this->curve->sign($h, $x, $s);

            return $this->convert->byteArrayToHexString(array_merge($v, $h));
        }



        function verifyBytes(signature, message, publicKey) {
            $signatureBytes = $this->convert->stringToByteArray($signature);
            $messageBytes = $this->convert->stringToByteArray($message);
            $publicKeyBytes = $this->convert->stringToByteArray($publicKey);
            $v = substr($signatureBytes, 0, 32);
            $h = substr($signatureBytes, 32);
            $y = $this->curve->verify($v, $h, $publicKeyBytes);

            $m = hash("sha256", hex2bin($this->convert->byteArrayToHexString($messageBytes));

            $h2 = hash("sha256", hex2bin($this->convert->byteArrayToHexString(array_merge($m, $y))));

            return $this->convert->areByteArraysEqual($h, $h2);
        }

}

class Converters {

    public function charToNibble($char)
    {
        switch($char)
        {
            case "0": return 0;
            case "1": return 1;
            case "2": return 2;
            case "3": return 3;
            case "4": return 4;
            case "5": return 5;
            case "6": return 6;
            case "7": return 7;
            case "8": return 8;
            case "9": return 9;
            case "a": return 10;
            case "A": return 10;
            case "b": return 11;
            case "B": return 11;
            case "c": return 12;
            case "C": return 12;
            case "d": return 13;
            case "D": return 13;
            case "e": return 14;
            case "E": return 14;
            case "f": return 15;
            case "F": return 15;
        }
        return 0;
    }


    function hexStringToByteArray($str) {

            $bytes = array();
            $i = 0;
            if (0 !== strlen($str) % 2) {
                array_push($bytes, $this->charToNibble($str[0]));
                ++$i;
            }

            for (; $i < strlen($str) - 1; $i += 2) {
                array_push($bytes, ($this->charToNibble($str[$i]) << 4) + $this->charToNibble($str[$i + 1]));

            }

            return $bytes;
    }

function byteArrayToHexString($bytes) {
    $nibbleToChar = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];

            $str = '';
            for ($i = 0; $i < count($bytes); ++$i) {
                if ($bytes[$i] < 0) {
                    $bytes[$i] += 256;
                }
                $str .= $nibbleToChar[$bytes[$i] >> 4] . $nibbleToChar[$bytes[$i] & 0x0F];
            }

            return $str;
        }

        function stringToByteArray($str) {
            //str = unescape(encodeURIComponent(str)); //temporary

            $bytes = array_pad(array(), strlen($str), 0);
            for ($i = 0; $i < strlen($str); ++$i)
                $bytes[$i] = ord($str[$i]);

            return $bytes;
        }

 function areByteArraysEqual($bytes1, $bytes2) {
        if (count($bytes1) !== count($bytes2))
            return false;

        for ($i = 0; $i < count($bytes1); ++$i) {
            if ($bytes1[$i] !== $bytes2[$i])
                return false;
        }

        return true;
    }


    function secretPhraseToPublicKey(secretPhrase) {
            $secretPhraseBytes = hexStringToByteArray($secretPhrase);
            $digest = hash("sha256", $secretPhrase);
            return byteArrayToHexString((new Curve25519())->keygen($digest)->p);
        }
    }

    function secretPhraseToPrivateKey($secretPhrase) {
        $h = hexStringToByteArray(hash("sha256", $secretPhrase));
        return byteArrayToHexString((new Curve25519())->clamp($h));
    }

    /*function secretPhraseToAccountId($secretPhrase) {
        return $this->getAccountIdFromPublicKey(NRS.getPublicKey(converters.stringToHexString(secretPhrase)));
    }

    function publicKeyToAccountId($publicKey) {
        $hex = $this->hexStringToByteArray($publicKey);

        _hash.init();
        _hash.update(hex);

        $account = hash("sha256", hex2bin($publicKey));

        $slice = substr(hexStringToByteArray($account),0, 8);

        var accountId = byteArrayToBigInteger(slice).toString();

        return accountId;
    }*/


}

    /* Ported to PHP from Javascript by <NAME> 1/29/15
 * Ported to JavaScript from Java 07/01/14.
 *
 * Ported from C to Java by <NAME> [sahn0], 23/02/08.
 * Original: http://cds.xs4all.nl:8081/ecdh/
 */
/* Generic 64-bit integer implementation of Curve25519 ECDH
 * Written by <NAME>, 200608242056
 * Public domain.
 *
 * Based on work by <NAME>, http://cr.yp.to/ecdh.html
 */

class Curve25519 {

{'fraction_non_alphanumeric': 0.16731734523145567, 'fraction_numerical': 0.03281279048150214, 'mean_word_length': 2.162551440329218, 'pattern_counts': {'":': 46, '<': 29, '<?xml version=': 0, '>': 104, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6216665', 'n_tokens_mistral': 3770, 'n_tokens_neox': 3385, 'n_words': 722}