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


C# Number.GetContinuousBitCount方法代码示例

本文整理汇总了C#中System.Number.GetContinuousBitCount方法的典型用法代码示例。如果您正苦于以下问题:C# Number.GetContinuousBitCount方法的具体用法?C# Number.GetContinuousBitCount怎么用?C# Number.GetContinuousBitCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Number的用法示例。


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

示例1: Multiply

		public unsafe ECPoint Multiply (Number scaler)
		{
			ECPoint[] P = SetupMultiplyHelperPoints ();
#if true
			scaler = new Number (scaler, 1);
			int l = scaler.BitCount () - 1;
			int *b = stackalloc int [l >> 2];
			int* e = stackalloc int[l >> 2];
			int d = ComputeSignedWindowDecomposition (scaler, b, e);
			ECPoint Q = P[b[d - 1]];
			for (int i = d - 2; i >= 0; i --) {
				for (int k = 0; k < e[i + 1] - e[i]; k ++)
					Q = Q.Double ();
				if (b[i] > 0)
					Q = Q.Add (P[b[i]]);
				else
					Q = Q.Add (P[-b[i]].Invert ());
			}
			for (int k = 0; k < e[0]; k++)
				Q = Q.Double ();
#else
#if true
			if (P == null) {
				P = _multiplyHelperPoints = new ECPoint[16];
				P[1] = this;
				P[2] = this.Double ();
				P[3] = P[1].Add (P[2]);
				P[5] = P[3].Add (P[2]);
				P[7] = P[5].Add (P[2]);
				P[9] = P[7].Add (P[2]);
				P[11] = P[9].Add (P[2]);
				P[13] = P[11].Add (P[2]);
				P[15] = P[13].Add (P[2]);
			}
			int j = scaler.BitCount () - 1;
			ECPoint Q = _field.GetInfinityPoint (_group);
			while (j >= 0) {
				if (scaler.GetBit (j) == 0) {
					Q = Q.Double ();
					j--;
				} else {
					int n = j - 1;
					uint h = (1 << 3) | (scaler.GetBit (n--) << 2) | (scaler.GetBit (n--) << 1) | scaler.GetBit (n);
					int t = j - 3;
					while ((h & 1) == 0) {
						h >>= 1;
						t++;
					}
					for (int i = 1; i <= j - t + 1; i++)
						Q = Q.Double ();
					Q = Q.Add (P[(int)h]);
					j = t - 1;
				}
			}
#else
			ECPoint inv = Invert ();
			if (P == null) {
				P = _multiplyHelperPoints = new ECPoint[16];
				P[1] = this;
				P[2] = this.Double ();
				P[3] = P[1].Add (P[2]);
				P[5] = P[3].Add (P[2]);
				P[7] = P[5].Add (P[2]);
				P[9] = P[7].Add (P[2]);
				P[11] = P[9].Add (P[2]);
				P[13] = P[11].Add (P[2]);
				P[15] = P[13].Add (P[2]);
			}
			int j = scaler.BitCount () - 1;
			ECPoint Q = _field.GetInfinityPoint (_group);
			while (j >= 0) {
				uint continuous = scaler.GetContinuousBitCount (j);
				if (continuous == 0) {
					Q = Q.Double ();
					j--;
				} else if (continuous <= 4) {
					int n = j - 1;
					uint h = (1 << 3) | (scaler.GetBit (n--) << 2) | (scaler.GetBit (n--) << 1) | scaler.GetBit (n);
					int t = j - 3;
					while ((h & 1) == 0) {
						h >>= 1;
						t++;
					}
					for (int i = 1; i <= j - t + 1; i++)
						Q = Q.Double ();
					Q = Q.Add (P[(int)h]);
					j = t - 1;
				} else {
					Q = Q.Add (this);
					for (uint i = 0; i < continuous; i ++)
						Q = Q.Double ();
					Q = Q.Add (inv);
					j -= (int)continuous;
				}
			}
#endif
#endif
			return Q;
		}
开发者ID:kazuki,项目名称:opencrypto.net,代码行数:99,代码来源:ECPoint.cs


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