<commit_before>﻿using NBitcoin.Crypto;
using NBitcoin.BouncyCastle.Math;
using System;
using System.Linq;
using System.Text;

namespace NBitcoin
{
	public class Key : IBitcoinSerializable, IDestination
	{
		private const int KEY_SIZE = 32;
		private readonly static uint256 N = uint256.Parse("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");

		public static Key Parse(string wif, Network network = null)
		{
			return Network.Parse<BitcoinSecret>(wif, network).PrivateKey;
		}

		public static Key Parse(string wif, string password, Network network = null)
		{
			return Network.Parse<BitcoinEncryptedSecret>(wif, network).GetKey(password);
		}

		byte[] vch = new byte[0];
		internal ECKey _ECKey;
		public bool IsCompressed
		{
			get;
			internal set;
		}

		public Key()
			: this(true)
		{

		}

		public Key(bool fCompressedIn)
		{
			var data = new byte[KEY_SIZE];
			do
			{
				RandomUtils.GetBytes(data);
			} while(!Check(data));

			SetBytes(data, data.Length, fCompressedIn);
		}
		public Key(byte[] data, int count = -1, bool fCompressedIn = true)
		{
			if(count == -1)
				count = data.Length;
			if(count != KEY_SIZE)
			{
				throw new FormatException("The size of an EC key should be 32");
			}
			if(Check(data))
			{
				SetBytes(data, count, fCompressedIn);
			}
			else<commit_msg>Key.cs: cosmetic, avoid magic number to fix DRY (#340)<commit_after>﻿using NBitcoin.Crypto;
using NBitcoin.BouncyCastle.Math;
using System;
using System.Linq;
using System.Text;

namespace NBitcoin
{
	public class Key : IBitcoinSerializable, IDestination
	{
		private const int KEY_SIZE = 32;
		private readonly static uint256 N = uint256.Parse("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");

		public static Key Parse(string wif, Network network = null)
		{
			return Network.Parse<BitcoinSecret>(wif, network).PrivateKey;
		}

		public static Key Parse(string wif, string password, Network network = null)
		{
			return Network.Parse<BitcoinEncryptedSecret>(wif, network).GetKey(password);
		}

		byte[] vch = new byte[0];
		internal ECKey _ECKey;
		public bool IsCompressed
		{
			get;
			internal set;
		}

		public Key()
			: this(true)
		{

		}

		public Key(bool fCompressedIn)
		{
			var data = new byte[KEY_SIZE];
			do
			{
				RandomUtils.GetBytes(data);
			} while(!Check(data));

			SetBytes(data, data.Length, fCompressedIn);
		}
		public Key(byte[] data, int count = -1, bool fCompressedIn = true)
		{
			if(count == -1)
				count = data.Length;
			if(count != KEY_SIZE)
			{
				throw new FormatException($"The size of an EC key should be {KEY_SIZE}");
			}
			if(Check(data))
			{
				SetBytes(data, count, fCompressedIn);
			}
			else
{'fraction_non_alphanumeric': 0.10859896219421794, 'fraction_numerical': 0.02112676056338028, 'mean_word_length': 3.7350877192982455, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1822491', 'n_tokens_mistral': 1109, 'n_tokens_neox': 919, 'n_words': 231}