• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UInt128类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: HostToNetworkOrder

        private static UInt128 HostToNetworkOrder(UInt128 value)
        {
            UInt128 result;

            unsafe
            {
                UInt128* resultPtr = &result;
                byte* resultBytePtr = (byte*)resultPtr;

                UInt128* valuePtr = &value;
                byte* valueBytePtr = (byte*)valuePtr;

                for (int i = 0; i != UInt128.SizeOf; ++i)
                    resultBytePtr[i] = valueBytePtr[UInt128.SizeOf - i - 1];
            }

            return result;
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:18,代码来源:ByteArrayExtensions.cs


示例17: GetBytes

		public static byte[] GetBytes(UInt128[] value, bool bigEndian, int index=0, int count=0)
		{
			return IsLittleEndian^bigEndian?GetBytes(value, index, count):GetBytesSwapped(value, index, count);
		}
开发者ID:csleead,项目名称:Free.Core,代码行数:4,代码来源:BitConverterPlus.cs


示例18: ToUInt128ArraySwapped

		public static UInt128[] ToUInt128ArraySwapped(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];
			for(int i=0; i<count; i++, index+=16)
				ret[i]=new UInt128(ToUInt64Swapped(value, index), ToUInt64Swapped(value, index+8));

			return ret;
		}
开发者ID:csleead,项目名称:Free.Core,代码行数:18,代码来源:BitConverterPlus.cs


示例19: Create

		/// <summary>
		/// Creates an instance of a CRC algorithm with the behaviour according to the parameters.
		/// </summary>
		/// <param name="polynomial">The polynomial to use. Unreflected and filled in the least significant bits without the leading 1.</param>
		/// <param name="init">The initial value of the register. Unreflected and filled in the least significant bits.</param>
		/// <param name="refIn">Set <b>true</b>, if input bits are reflected. Least significant bits first.</param>
		/// <param name="refOut">Set <b>true</b>, if register is to be reflected before XORing with <paramref name="xorOut"/> and output.</param>
		/// <param name="xorOut">Value to be XORed with the reflected or unreflected register depending on <paramref name="refOut"/> before output. Filled in the least significant bits.</param>
		/// <param name="width">The width of the polynomial in bits. Must be greater than 0 and less than 129. Default is 128.</param>
		/// <returns>The created instance.</returns>
		public static ICRC<UInt128> Create(UInt128 polynomial, UInt128 init, bool refIn, bool refOut, UInt128 xorOut, int width = 128)
		{
			if (refIn) return new ReflectedUInt128(polynomial, init, refOut, xorOut, width);
			return new UnreflectedUInt128(polynomial, init, refOut, xorOut, width);
		}
开发者ID:Xevle,项目名称:Xevle.Data,代码行数:15,代码来源:CRC.Factories.cs


示例20: Power

 public static UInt128 Power(UInt128 value, UInt128 exponent)
 {
     UInt128 result;
     UInt128.Pow(out result, ref value, (uint)exponent);
     return result;
 }
开发者ID:ricksladkey,项目名称:Dirichlet,代码行数:6,代码来源:Power.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UInt16类代码示例发布时间:2022-05-24
下一篇:
C# UIWindow类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap