【发布时间】:2010-05-14 16:46:57
【问题描述】:
在下面的 sn-p 中,请从第一个“for”循环开始解释发生了什么以及为什么。为什么加0,为什么在第二个循环中加1。 bigi 下的“if”语句中发生了什么。最后解释一下modPow方法。提前感谢您的有意义的答复。
public static boolean isPrimitive(BigInteger m, BigInteger n) {
BigInteger bigi, vectorint;
Vector<BigInteger> v = new Vector<BigInteger>(m.intValue());
int i;
for (i=0;i<m.intValue();i++)
v.add(new BigInteger("0"));
for (i=1;i<m.intValue();i++)
{
bigi = new BigInteger("" + i);
if (m.gcd(bigi).intValue() == 1)
v.setElementAt(new BigInteger("1"), n.modPow(bigi,m).intValue());
}
for (i=0;i<m.intValue();i++)
{
bigi = new BigInteger("" + i);
if (m.gcd(bigi).intValue() == 1)
{
vectorint = v.elementAt(bigi.intValue());
if ( vectorint.intValue() == 0)
i = m.intValue() + 1;
}
}
if (i == m.intValue() + 2)
return false;
else
return true;
}
【问题讨论】:
-
这显然是功课。我的问题是:为什么人们甚至不倾向于将问题的文本更改为看起来与典型的家庭作业问题有些不同? “最后解释一下 modPow 方法。”.. 这让我哈哈大笑。
标签: vector root primitive diffie-hellman