void Update() { if (!curUnit) { stats.gameObject.SetActive(false); avatar.gameObject.SetActive(false); health.gameObject.SetActive(false); } else { aliveUI.gameObject.SetActive(true); stats.gameObject.SetActive(true); int atkExp = (int)BigInteger.Log10(curUnit.top); int defExp = (int)BigInteger.Log10(curUnit.bot); stats.text = ""; stats.text += curUnit.GetTopAlias() + " " + BigIntegerUtilities.ToString(curUnit.top, 5, 8); stats.text += "\n"; stats.text += curUnit.GetBotAlias() + " " + BigIntegerUtilities.ToString(curUnit.bot, 5, 8); avatar.gameObject.SetActive(true); avatar.sprite = curUnit.avatar; health.gameObject.SetActive(true); health.value = curUnit.HPPercentage; healthFill.color = curUnit.GetClassColor(); } }
public void TestPublicPoints() { var points = new List <PubPointTestData>(); points.Add(new PubPointTestData(7, "5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc", "6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da")); points.Add(new PubPointTestData(1485, "c982196a7466fbbbb0e27a940b6af926c1a74d5ad07128c82824a11b5398afda", "7a91f9eae64438afb9ce6448a1c133db2d8fb9254e4546b6f001637d50901f55")); points.Add(new PubPointTestData(BigInteger.Pow(2, 128), "8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da", "662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82")); points.Add(new PubPointTestData(BigInteger.Pow(2, 240) + BigInteger.Pow(2, 31), "9577ff57c8234558f293df502ca4f09cbc65a6572c842b39b366f21717945116", "10b49c67fa9365ad7b90dab070be339a1daf9052373ec30ffae4f72d5e66d053")); foreach (var point in points) { var expectedX = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(point.X); var expectedY = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(point.Y); // Using Private/Public Key classes var prvKey = new PrivateKey(point.Secret); var pubKey = prvKey.GetPublicKey(); Assert.AreEqual(expectedX, pubKey.X); Assert.AreEqual(expectedY, pubKey.Y); // Manual check var pubPoint = BitcoinConstants.G.Multiply(point.Secret); Assert.AreEqual(expectedX, pubPoint.X.Num); Assert.AreEqual(expectedY, pubPoint.Y.Num); } }
public void BigIntegerToHexTest() { var val = new BigInteger(0x1234567890ABCDEF); var expected = "1234567890abcdef"; var hexLower = val.PositiveValToHexString(); Assert.AreEqual(expected, hexLower); hexLower = val.PositiveValToHexString(true); Assert.AreEqual(expected, hexLower); expected = "1234567890ABCDEF"; var hexUpper = val.PositiveValToHexString(false); Assert.AreEqual(expected, hexUpper); val = new BigInteger(0x00005678FF); expected = "5678ff"; var hexStr = val.PositiveValToHexString(); Assert.AreEqual(expected, hexStr); val = new BigInteger(0x00005678FF); expected = "00005678ff"; hexStr = val.PositiveValToHexString(10); Assert.AreEqual(expected, hexStr); val = new BigInteger(0x5678FF); expected = "0005678ff"; hexStr = val.PositiveValToHexString(9); Assert.AreEqual(expected, hexStr); expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"; val = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(expected); hexStr = val.PositiveValToHexString(64, false); Assert.AreEqual(expected, hexStr); var input = "0000000000000000000000000000000EBAAEDCE6AF48A03BBFD25E8CD0364141"; expected = "EBAAEDCE6AF48A03BBFD25E8CD0364141"; val = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(input); hexStr = val.PositiveValToHexString(false); Assert.AreEqual(expected, hexStr); input = "EBAAEDCE6AF48A03BBFD25E8CD0364141"; expected = "0000000000000000000000000000000EBAAEDCE6AF48A03BBFD25E8CD0364141"; val = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(input); hexStr = val.PositiveValToHexString(64, false); Assert.AreEqual(expected, hexStr); }
public void CoordinateTest() { // Uncompressed Public Key var xValStr = "50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352"; var yValStr = "2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"; var xVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(xValStr); var yVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(yValStr); var point = new Secp256k1Point(xVal, yVal); var xValStr2 = point.X.Num.PositiveValToHexString(false); var yValStr2 = point.Y.Num.PositiveValToHexString(false); Assert.AreEqual(xValStr, xValStr2); Assert.AreEqual(yValStr, yValStr2); }
public void BigIntegerToBytesTest() { // Uncompressed Public Key var xValStr = "50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352"; var yValStr = "2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"; var expected = "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"; var xVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(xValStr); var yVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(yValStr); var bytes = new byte[65]; // type byte + 32 bytes for X + 32 bytes for Y bytes[0] = 0x04; xVal.PositiveValToBigEndianBytes(bytes, 1, 32); yVal.PositiveValToBigEndianBytes(bytes, 33, 32); var hexStr = HexUtilities.BytesToHexString(bytes, false); Assert.AreEqual(expected, hexStr); // Arbitrary data to arbitrary position in buffer var str1 = "010203040506"; var str2 = "ABCDEF"; expected = "010203040506000000ABCDEF"; var val1 = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(str1); var val2 = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(str2); bytes = new byte[12]; val1.PositiveValToBigEndianBytes(bytes, 0, 6); val2.PositiveValToBigEndianBytes(bytes, 9, 3); hexStr = HexUtilities.BytesToHexString(bytes, false); Assert.AreEqual(expected, hexStr); // Arbitrary data to arbitrary position in buffer, right aligned str1 = "010203040506"; str2 = "ABCDEF"; expected = "010203040506000000ABCDEF"; val1 = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(str1); val2 = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(str2); bytes = new byte[12]; val1.PositiveValToBigEndianBytes(bytes, 0, 6); val2.PositiveValToBigEndianBytes(bytes, 6, 6); hexStr = HexUtilities.BytesToHexString(bytes, false); Assert.AreEqual(expected, hexStr); }
public void GenerateWifStringTest() { // Compressed var prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD"); var expected = "KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ"; var prvKey = new PrivateKey(prvKeyVal, false, true); var wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD"); expected = "L5oLkpV3aqBJ4BgssVAsax1iRa77G5CVYnv9adQ6Z87te7TyUdSC"; prvKey = new PrivateKey(BigInteger.Pow(2, 256) - BigInteger.Pow(2, 199), false, true); wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("1cca23de92fd1862fb5b76e5f4f50eb082165e5191e116c18ed1a6b24be6a53f"); expected = "cNYfWuhDpbNM1JWc3c6JTrtrFVxU4AGhUKgw5f93NP2QaBqmxKkg"; prvKey = new PrivateKey(prvKeyVal, true, true); wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); // Uncompressed prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD"); expected = "5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn"; prvKey = new PrivateKey(prvKeyVal, false, false); wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"); expected = "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"; prvKey = new PrivateKey(prvKeyVal, false, false); wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("0dba685b4511dbd3d368e5c4358a1277de9486447af7b3604a69b8d9d8b7889d"); expected = "5HvLFPDVgFZRK9cd4C5jcWki5Skz6fmKqi1GQJf5ZoMofid2Dty"; prvKey = new PrivateKey(prvKeyVal, false, false); wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); expected = "93XfLeifX7Jx7n7ELGMAf1SUR6f9kgQs8Xke8WStMwUtrDucMzn"; prvKey = new PrivateKey(BigInteger.Pow(2, 256) - BigInteger.Pow(2, 201), true, false); wifString = prvKey.GetWifString(); Assert.AreEqual(expected, wifString); }
public void Update() { unitToSummon.name = nameField.text; unitToSummon.avatar = image.sprite; unitToSummon.maxHp = player.newUnitPool * player.hpMultiplier; unitToSummon.top = player.newUnitPool * ((int)atkSlider.value * 10 / (int)atkSlider.maxValue) / 10; unitToSummon.bot = player.newUnitPool * ((int)defSlider.value * 10 / (int)defSlider.maxValue) / 10; atkNameplate.text = unitToSummon.GetTopAlias(); defNameplate.text = unitToSummon.GetBotAlias(); poolText.text = BigIntegerUtilities.ToString(player.newUnitPool, 5); hpText.text = BigIntegerUtilities.ToString(unitToSummon.maxHp, 5); atkText.text = BigIntegerUtilities.ToString(unitToSummon.top, 5); defText.text = BigIntegerUtilities.ToString(unitToSummon.bot, 5); }
public void TestVerify() { var x = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("887387e452b8eacc4acfde10d9aaf7f6d9a0f975aabb10d006e4da568744d06c"); var y = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("61de6d95231cd89026e286df3b6ae4a894a3378e393e93a0f45b666329a0ae34"); var p = new PublicKey(x, y); var z = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("ec208baa0fc1c19f708a9ca96fdeff3ac3f230bb4a7ba4aede4942ad003c0f60"); var r = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("ac8d1c87e51d0d441be8b3dd5b05c8795b48875dffe00b7ffcfac23010d3a395"); var s = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("68342ceff8935ededd102dd876ffd6ba72d6a427a3edb13d26eb0781cb423c4"); var signature = new Signature(r, s); var valid = p.Verify(z, signature); Assert.IsTrue(valid); z = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("7c076ff316692a3d7eb3c3bb0f8b1488cf72e1afcd929e29307032997a838a3d"); r = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("eff69ef2b1bd93a66ed5219add4fb51e11a840f404876325a1e8ffe0529a2c"); s = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString("c7207fee197d27c618aea621406f6bf5ef6fca38681d82b2f06fddbdce6feab6"); signature = new Signature(r, s); valid = p.Verify(z, signature); Assert.IsTrue(valid); }
void Update() { if (!curUnit) { gameObject.SetActive(false); } else { nameText.text = curUnit.name; nameText.color = curUnit.GetClassColor(); avatar.sprite = curUnit.avatar; classText.text = curUnit.GetClassName().ToUpper(); classText.color = curUnit.GetClassColor(); atkNameplate.text = curUnit.GetTopAlias(); defNameplate.text = curUnit.GetBotAlias(); maxHpValue.text = BigIntegerUtilities.ToString(curUnit.maxHp, 8); hpValue.text = BigIntegerUtilities.ToString(curUnit.hp, 8); atkValue.text = BigIntegerUtilities.ToString(curUnit.top, 8); defValue.text = BigIntegerUtilities.ToString(curUnit.bot, 8); expValue.text = BigIntegerUtilities.ToString(curUnit.exp, 8); if (curUnit.curWorld) { notDeployedUI.gameObject.SetActive(false); deployedUI.gameObject.SetActive(true); worldText.text = curUnit.curWorld.displayName; worldImage.sprite = curUnit.curWorld.sprite; worldImage.gameObject.SetActive(true); floorText.text = "F" + BigIntegerUtilities.ToString(curUnit.curFloor, 8); floorText.gameObject.SetActive(true); } else { deployedUI.gameObject.SetActive(false); notDeployedUI.gameObject.SetActive(true); worldImage.gameObject.SetActive(false); floorText.gameObject.SetActive(false); } } }
public void AddressTest() { // Uncompressed Public Key var ecdsaPrivateKey = "18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725"; var expectedPubXVal = "50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352"; var expectedPubYVal = "2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"; var expectedPubKey = "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"; var expectedAddress = "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"; var prvKeyVal = BigIntegerUtilities.CreateFromUnsignedBigEndianHexString(ecdsaPrivateKey); var prvKey = new PrivateKey(prvKeyVal, false, false); var pubKey = prvKey.GetPublicKey(); Assert.AreEqual(expectedPubXVal, pubKey.X.PositiveValToHexString(false)); Assert.AreEqual(expectedPubYVal, pubKey.Y.PositiveValToHexString(false)); var pubKeyBytes = pubKey.GetPublicKeyBytes(); var pubKeyString = HexUtilities.BytesToHexString(pubKeyBytes, false); Assert.AreEqual(expectedPubKey, pubKeyString); var address = pubKey.GetAddress(); Assert.AreEqual(expectedAddress, address); }