3

私は多数を使用する暗号化アルゴリズムを実装しているため、Java アプリケーションを作成する際にクラス BigInteger を使用する必要があります。

ただし、Androidアプリケーションで同じものを実装しようとすると、コンストラクター

public BigInteger(int bitLength,int certainty,Random rnd), 

ランダムな BigInteger は生成されません (同じ整数が何度も生成されます 35879 :P)。単純な Java アプリケーションで、ランダムな BigInteger が正常に生成されます。

参考までに、

http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#constructor_detail

また、 java.util.* の形式のものをインポートするかどうか教えてください。どの Android アプリケーションでも動作すると予想されますか??

Android が BigInteger をサポートしていない場合、またはサポートされているクラスと同様のクラスが他に存在する場合は、コメントしてください。

ここでは、メソッド systemoutprintln() を使用して、それぞれの文字列をレイアウトに出力しています。

ここにあなたの参照のためのコードがあります、

public class keyGenerator {

/**
 * @param args the command line arguments
 */

  static  Vector check = new Vector();


  static protected BigInteger p= new BigInteger("161");
  static protected BigInteger q= new BigInteger("47");
  static protected Random s =new Random();
  static protected BigInteger n = new BigInteger("1");
  static protected BigInteger trails;
  static protected BigInteger lambda ;
  static protected BigInteger nsq  = new BigInteger("1");
  static protected BigInteger g = new BigInteger("1");
  static protected BigInteger temp = new BigInteger("1");
  static protected long timetkn;
  static protected View myview;
  static protected String[] printarray = new String[1000];
  static protected int ii=0;

static protected int maxbit;
private static BigInteger two = new BigInteger("2");

public keyGenerator() {

  //  Activity activity = new Activity();
// et.append("Second Part!!");
// EditText et = (EditText)activity.findViewById(R.string.second);
//    et.append("Working");


    long keyStart = SystemClock.uptimeMillis();
    p = new BigInteger(7,1,s);

            Systemoutprintln("Assumed p :" +p.toString());
  /*  while(!isPrime(p) && ( (p.compareTo(two)==1) || (p.compareTo(two))==0) )
    {
            p = new BigInteger(7,1,s);

    Systemoutprintln(p.toString());
    }*/


    Systemoutprintln("Assumed q :" +p.toString());
    q = new BigInteger(7,1,s);
4

2 に答える 2

3

ドキュメントを見ると、呼び出しているコンストラクターの rand 引数が使用されていないことがわかります。

Implementation Note: the Random argument is ignored. This implementation uses OpenSSL's bn_rand as a source of cryptographically strong pseudo-random numbers.

おそらくそれを削除して引数として null を指定するか、確実性引数を削除します。その場合、 Random オブジェクトが使用されます(ドキュメントによると)。

于 2012-11-12T21:26:59.277 に答える
2

乱数に関するJavaドキュメントによると、これは機能するはずです。ただし、2 つの異なるラベルで bigInteger p を 2 回印刷していることに気付きました。それらを混同している可能性はほとんどありませんか?

編集:digitaljoelの助けを借りて、この以前のクエストを見つけました:

OpenSSL の bn_rand_range に相当する Java はありますか?

基本的に、SecureRandom を使用し、そこで指定されたメソッドを使用する必要があります。

Random r = new SecureRandom();    
BigInteger q = something_big;
BigInteger ans;

do
    BigInteger(bits_in_q, r);
while (ans > q)
于 2012-11-12T21:24:06.990 に答える