当前位置: 首页>>代码示例>>C#>>正文


C# UInt128类代码示例

本文整理汇总了C#中UInt128的典型用法代码示例。如果您正苦于以下问题:C# UInt128类的具体用法?C# UInt128怎么用?C# UInt128使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UInt128类属于命名空间,在下文中一共展示了UInt128类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: generate_key_secret

    /*--------------------------------------------------------------------------*/
    public static byte[] generate_key_secret(byte[] my_private, byte[] another_public)
    {
        if (my_private == null || my_private.Length != DH_KEY_LENGTH) return null;
        if (another_public == null || another_public.Length != DH_KEY_LENGTH) return null;

        UInt128 private_k = new UInt128(my_private);
        UInt128 another_k = new UInt128(another_public);

        /* secret_key = other_key^prv_key mod P*/
        UInt128 secret_k = UInt128._powmodp(another_k, private_k);
        byte[] secret_key = new byte[DH_KEY_LENGTH];
        secret_k.to_bytes(secret_key);
        return secret_key;
    }
开发者ID:exat500g,项目名称:dhexchange,代码行数:15,代码来源:DHExchange.cs

示例2: UInt128_Equals_Equivalent_ReturnsTrue

        public void UInt128_Equals_Equivalent_ReturnsTrue()
        {
            var baseValue = new UInt128() { High = 1, Low = 2 };

            var testValues = new object[] { 
                baseValue, 
                new UInt128() { High = 1, Low = 2 } 
            };

            foreach (var testValue in testValues)
            {
                Assert.True(
                    baseValue.Equals(testValue));
            }
        }
开发者ID:PragmaticIT,项目名称:Data.HashFunction,代码行数:15,代码来源:UInt128Tests.cs

示例3: UInt128_Equals_Inequivalent_ReturnsFalse

        public void UInt128_Equals_Inequivalent_ReturnsFalse()
        {
            var baseValue = new UInt128() { High = 1, Low = 2 };

            var testValues = new object[] {
                null, 
                "", 
                new UInt128() { Low = 2 }, 
                new UInt128 { High = 1 } 
            };

            
            foreach (var testValue in testValues)
            {
                Assert.False(
                    baseValue.Equals(testValue));
            }
        }
开发者ID:PragmaticIT,项目名称:Data.HashFunction,代码行数:18,代码来源:UInt128Tests.cs

示例4: generate_key_pair

    /*--------------------------------------------------------------------------*/
    public static void generate_key_pair(byte[] public_key, byte[] private_key)
    {
        if (public_key == null || public_key.Length != DH_KEY_LENGTH) return;
        if (private_key == null || private_key.Length != DH_KEY_LENGTH) return;

        Random rand = new Random();

        /* generate random private key */
        for (int i = 0; i < DH_KEY_LENGTH; i++)
        {
            private_key[i] = (byte)(rand.Next() & 0xFF);
        }

        /* pub_key = G^prv_key mod P*/
        UInt128 private_k = new UInt128(private_key);
        UInt128 public_k = UInt128._powmodp(G, private_k);

        public_k.to_bytes(public_key);
    }
开发者ID:exat500g,项目名称:dhexchange,代码行数:20,代码来源:DHExchange.cs

示例5: IpV6Address

        /// <summary>
        /// Creates an address from an address string ("2001:0db8:0::22:1.2.3.4").
        /// </summary>
        public IpV6Address(string value)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            string cannonizedValue = value;

            // Handle ...:1.2.3.4
            int lastColonIndex = cannonizedValue.LastIndexOf(':');
            if (lastColonIndex == -1)
                throw new ArgumentException("Invalid IPv6 address format " + value);

            string lastPart = value.Substring(lastColonIndex + 1, cannonizedValue.Length - lastColonIndex - 1);
            if (lastPart.IndexOf('.') != -1)
            {
                uint lastPartValue = new IpV4Address(lastPart).ToValue();
                cannonizedValue = cannonizedValue.Substring(0, lastColonIndex + 1) +
                                  (lastPartValue >> 16).ToString("x", CultureInfo.InvariantCulture) + ":" + (lastPartValue & 0x0000FFFF).ToString("x", CultureInfo.InvariantCulture);
            }

            // Handle ...::...
            int doubleColonIndex = cannonizedValue.IndexOf("::", StringComparison.Ordinal);
            if (doubleColonIndex != -1)
            {
                int numMissingColons = 7 - cannonizedValue.Count(':');
                if (numMissingColons < 0)
                    throw new ArgumentException("Invalid IPv6 address format " + value);
                cannonizedValue = cannonizedValue.Substring(0, doubleColonIndex + 2) +
                                  new string(':', numMissingColons) +
                                  cannonizedValue.Substring(doubleColonIndex + 2);
            }

            IEnumerable<ushort> values =
                cannonizedValue.Split(':').Select(part => string.IsNullOrEmpty(part) ? (ushort)0 : ushort.Parse(part, NumberStyles.HexNumber, CultureInfo.InvariantCulture));

            ulong mostSignificant = values.Take(4).Aggregate((ulong)0, (sum, element) => (sum << 16) + element);
            ulong leastSignificant = values.Skip(4).Take(4).Aggregate((ulong)0, (sum, element) => (sum << 16) + element);

            _value = new UInt128(mostSignificant, leastSignificant);
        }
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:43,代码来源:IpV6Address.cs

示例6: SumTest

        public void SumTest()
        {
            UInt128 value1 = 0;
            UInt128 value2 = 0;
            Assert.AreEqual<UInt128>(0, value1 + value2);

            value1 = 1;
            Assert.AreEqual<UInt128>(1, value1 + value2);
            
            value2 = 1;
            Assert.AreEqual<UInt128>(2, value1 + value2);

            value1 = 100;
            Assert.AreEqual<UInt128>(101, value1 + value2);

            value2 = 1000;
            Assert.AreEqual<UInt128>(1100, value1 + value2);

            value1 = ulong.MaxValue;
            value2 = 0;
            Assert.AreEqual(ulong.MaxValue, value1 + value2);

            value2 = 1;
            Assert.AreEqual(new UInt128(1,0), value1 + value2);

            value2 = 2;
            Assert.AreEqual(new UInt128(1, 1), value1 + value2);

            value2 = ulong.MaxValue;
            Assert.AreEqual(new UInt128(1, ulong.MaxValue - 1), value1 + value2);

            value1 = 2;
            value2 = new UInt128(1000, ulong.MaxValue);
            Assert.AreEqual(new UInt128(1001, 1), value1 + value2);

            value1 = new UInt128(100, ulong.MaxValue / 2 + 1);
            value2 = new UInt128(1000, ulong.MaxValue / 2 + 2);
            Assert.AreEqual(new UInt128(1101, 1), value1 + value2);

            value1 = new UInt128(ulong.MaxValue / 2, ulong.MaxValue / 2 + 1);
            value2 = new UInt128(ulong.MaxValue / 2, ulong.MaxValue / 2 + 2);
            Assert.AreEqual(new UInt128(ulong.MaxValue, 1), value1 + value2);

            value1 = new UInt128(ulong.MaxValue / 2 + 1, ulong.MaxValue / 2 + 1);
            value2 = new UInt128(ulong.MaxValue / 2, ulong.MaxValue / 2 + 2);
            Assert.AreEqual(new UInt128(0, 1), value1 + value2);
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:47,代码来源:UInt128Tests.cs

示例7: Square

 public static UInt128 Square(UInt128 a)
 {
     return UInt128.Square(a);
 }
开发者ID:ricksladkey,项目名称:Dirichlet,代码行数:4,代码来源:Power.cs

示例8: ModularDifference

 public static UInt128 ModularDifference(UInt128 a, UInt128 b, UInt128 modulus)
 {
     return UInt128.ModSub(a, b, modulus);
 }
开发者ID:ricksladkey,项目名称:Dirichlet,代码行数:4,代码来源:ModularDifference.cs

示例9: GetBytesSwapped

		public static unsafe byte[] GetBytesSwapped(UInt128 value)
		{
			byte* ptrHigh=(byte*)&value.High;
			byte* ptrLow=(byte*)&value.Low;
			return new byte[16] {
				ptrHigh[7], ptrHigh[6], ptrHigh[5], ptrHigh[4], ptrHigh[3], ptrHigh[2], ptrHigh[1], ptrHigh[0],
				ptrLow[7], ptrLow[6], ptrLow[5], ptrLow[4], ptrLow[3], ptrLow[2], ptrLow[1], ptrLow[0] };
		}
开发者ID:csleead,项目名称:Free.Core,代码行数:8,代码来源:BitConverterPlus.cs

示例10: ToUInt128Array

		public static unsafe UInt128[] ToUInt128Array(byte[] value, int index=0, int count=0)
		{
			if(value==null) throw new ArgumentNullException("value");

			if(index<0||index>value.Length)
				throw new ArgumentOutOfRangeException("index", "Must be non-negative and less than or equal to the length of value.");

			if(count<0) throw new ArgumentOutOfRangeException("count", "Must be non-negative.");
			if(index+count*16>value.Length) throw new ArgumentOutOfRangeException("count", "Must be less than or equal to the length of the byte array minus the offset argument divided by 16.");

			if(count==0) count=(value.Length-index)/16;

			UInt128[] ret=new UInt128[count];
			fixed(byte* ptr=&value[index])
				for(int i=0; i<count; i++) ret[i]=new UInt128(*((ulong*)ptr+2*i+1), *((ulong*)ptr+2*i));
			return ret;
		}
开发者ID:csleead,项目名称:Free.Core,代码行数:17,代码来源:BitConverterPlus.cs

示例11: Combine

		/// <summary>
		/// Combines the CRCs of two blocks to the CRC of the blocks concatenated.
		/// </summary>
		/// <param name="crc1">The CRC of the first block.</param>
		/// <param name="crc2">The CRC of the second block.</param>
		/// <param name="lengthOfCRC2">The length of the second block in bytes.</param>
		/// <param name="polynomial">The polynomial used to create the CRCs. Unreflected and filled in the least significant bits.</param>
		/// <returns>The combined CRC value.</returns>
		public static UInt128 Combine(UInt128 crc1, UInt128 crc2, int lengthOfCRC2, UInt128 polynomial)
		{
			return Combine(crc1, crc2, lengthOfCRC2, polynomial, UInt128.Zero, false, UInt128.Zero, 128);
		}
开发者ID:shintadono,项目名称:Free.Crypto,代码行数:12,代码来源:CRC.Combine.cs

示例12: MatrixSquare

		/// <summary>
		/// Squares a matrix (MOD 2). This method doesn't check the input arguments for
		/// performance reasons, so please make sure they are correct.
		/// </summary>
		/// <param name="result">The matrix for the result. Must be at least <paramref name="width"/> long.</param>
		/// <param name="matrix">The matrix to be squared. Must be at least <paramref name="width"/> long.</param>
		/// <param name="width">The width of the matrix. Default is 128.</param>
		static void MatrixSquare(UInt128[] result, UInt128[] matrix, int width=128)
		{
			UInt128[] res=result;
			UInt128[] mat=matrix;
			for(int n=0; n<width; n++) res[n]=MatrixMult(mat, mat[n]);
		}
开发者ID:shintadono,项目名称:Free.Crypto,代码行数:13,代码来源:CRC.Combine.cs

示例13: MatrixMult

		/// <summary>
		/// Multiplication of matrix with vector (MOD 2). This method doesn't check the
		/// input arguments for performance reasons, so please make sure they are correct.
		/// </summary>
		/// <param name="matrix">The matrix to multiply with.</param>
		/// <param name="vector">The vector to be multiplied with the matrix.</param>
		/// <returns>The resulting vector.</returns>
		static UInt128 MatrixMult(UInt128[] matrix, UInt128 vector)
		{
			int index=0;
			UInt128[] mat=matrix;
			UInt128 vec=vector;

			UInt128 ret=0;

			while(vec!=0)
			{
				if((vec.Low&1)!=0) ret^=mat[index];
				vec>>=1;
				index++;
			}

			return ret;
		}
开发者ID:shintadono,项目名称:Free.Crypto,代码行数:24,代码来源:CRC.Combine.cs

示例14: AssertValue

 public static void AssertValue(this XElement element, UInt128 expectedValue)
 {
     element.AssertValue(expectedValue.ToString("x32"));
 }
开发者ID:amitla,项目名称:Pcap.Net,代码行数:4,代码来源:XElementExtensions.cs

示例15: Write

 /// <summary>
 /// Writes the given value to the buffer using the given endianity and increments the offset by the number of bytes written.
 /// </summary>
 /// <param name="buffer">The buffer to write the value to.</param>
 /// <param name="offset">The offset in the buffer to start writing.</param>
 /// <param name="value">The value to write.</param>
 /// <param name="endianity">The endianity to use when converting the value to bytes.</param>
 public static void Write(this byte[] buffer, ref int offset, UInt128 value, Endianity endianity)
 {
     buffer.Write(offset, value, endianity);
     offset += UInt128.SizeOf;
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:12,代码来源:ByteArrayExtensions.cs


注:本文中的UInt128类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。