Esempio n. 1
0
        static void Main(string[] args)
        {
            //Pair<BigInteger> test = new Pair<BigInteger>();
            Util       test    = new Util();
            string     s       = "hello world";
            BigInteger integer = test.StringToBigInteger(s);
            //Console.WriteLine(integer);
            string temp = test.IntegerToBiginteger(integer);

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            //Console.WriteLine(temp);

            Accumulator accu1 = new Accumulator();

            java.math.BigInteger mem      = new EnhancedRandom().nextBigInteger();
            java.math.BigInteger a1       = accu1.add(mem);
            java.math.BigInteger witness1 = accu1.proveMembership(mem);
            java.math.BigInteger nonce1   = accu1.getNonce(mem);
            java.math.BigInteger n1       = accu1.getN();
            stopwatch.Start();


            bool tag;

            for (int i = 0; i < 1000; i++)
            {
                tag = Accumulator.verifyMembership(a1, mem, nonce1, witness1, n1);
            }
            stopwatch.Stop();
            TimeSpan span = stopwatch.Elapsed;

            Console.WriteLine(span.Milliseconds);
            Console.WriteLine("completed");
        }
 /** Set up a local evaluator for a nested function call. The evaluator gets the definition
  *  tree of the function; the set of all defined functions (to find locally called ones); a
  *  pointer to the global variable memory; and the value of the function parameter to be
  *  added to the local memory.
  */
 private ProfileTreeGrammar(CommonTree function,
              List<CommonTree> functionDefinitions,
              IDictionary<string, BigInteger> globalMemory,
              BigInteger paramValue)
     // Expected tree for function: ^(FUNC ID ( INT | ID ) expr)
     : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions)
 {
     this.globalMemory = globalMemory;
     localMemory[function.GetChild(1).Text] = paramValue;
 }
Esempio n. 3
0
        public BigInteger(ulong ulongValue)
        {
            var long31 = (long)(ulongValue & System.Int64.MaxValue);

            v = java.math.BigInteger.valueOf(long31);
            if (long31 != (long)ulongValue)
            {
                v = v.add(java.math.BigInteger.ONE.shiftLeft(63));
            }
        }
Esempio n. 4
0
 /** Set up a local evaluator for a nested function call. The evaluator gets the definition
  *  tree of the function; the set of all defined functions (to find locally called ones); a
  *  pointer to the global variable memory; and the value of the function parameter to be
  *  added to the local memory.
  */
 private ProfileTreeGrammar(CommonTree function,
                            List <CommonTree> functionDefinitions,
                            IDictionary <string, BigInteger> globalMemory,
                            BigInteger paramValue)
 // Expected tree for function: ^(FUNC ID ( INT | ID ) expr)
     : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions)
 {
     this.globalMemory = globalMemory;
     localMemory[function.GetChild(1).Text] = paramValue;
 }
Esempio n. 5
0
 public static java.math.BigInteger toBigInteger(byte[] array, int offset, int length
                                                 )
 {
     java.math.BigInteger result = new java.math.BigInteger(1, new byte[] { });
     for (int i = offset + length - 1; i >= offset; i--)
     {
         result = result.shiftLeft(8);
         result = result.or(java.math.BigInteger.valueOf(array[i] & unchecked ((int)0xFF)
                                                         ));
     }
     return(result);
 }
Esempio n. 6
0
 public virtual global::java.math.BigInteger[] divideAndRemainder(java.math.BigInteger arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaArrayObject <java.math.BigInteger>(@__env.CallObjectMethod(this.JvmHandle, global::java.math.BigInteger._divideAndRemainder13544, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.math.BigInteger[]);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaArrayObject <java.math.BigInteger>(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::java.math.BigInteger.staticClass, global::java.math.BigInteger._divideAndRemainder13544, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.math.BigInteger[]);
     }
 }
Esempio n. 7
0
 public virtual global::java.math.BigInteger modInverse(java.math.BigInteger arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::java.math.BigInteger._modInverse13550, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.math.BigInteger);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::java.math.BigInteger.staticClass, global::java.math.BigInteger._modInverse13550, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.math.BigInteger);
     }
 }
Esempio n. 8
0
 public virtual int compareTo(java.math.BigInteger arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(@__env.CallIntMethod(this.JvmHandle, global::java.math.BigInteger._compareTo13526, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
     else
     {
         return(@__env.CallNonVirtualIntMethod(this.JvmHandle, global::java.math.BigInteger.staticClass, global::java.math.BigInteger._compareTo13526, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
 }
        public object ConvertFrom(byte[] bytes)
        {
            byte[] scaleB = new byte[4];
            for (int i = 0; i < 4; i++)
                scaleB[3 - i] = bytes[i];

            int scale = BitConverter.ToInt32(scaleB, 0);

            byte[] bibytes = new byte[bytes.Length - 4];
            for (int i = 0; i < bibytes.Length; i++)
                bibytes[i] = bytes[i + 4];

            java.math.BigInteger bi = new java.math.BigInteger(bibytes);
            return new java.math.BigDecimal(bi, scale);
        }
Esempio n. 10
0
        public object ConvertFrom(byte[] bytes)
        {
            byte[] scaleB = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                scaleB[3 - i] = bytes[i];
            }

            int scale = BitConverter.ToInt32(scaleB, 0);

            byte[] bibytes = new byte[bytes.Length - 4];
            for (int i = 0; i < bibytes.Length; i++)
            {
                bibytes[i] = bytes[i + 4];
            }

            java.math.BigInteger bi = new java.math.BigInteger(bibytes);
            return(new java.math.BigDecimal(bi, scale));
        }
 /** Find matching function definition for a function name and parameter
  *  value. The first definition is returned where (a) the name matches
  *  and (b) the formal parameter agrees if it is defined as constant.
  */
 private CommonTree findFunction(string name, BigInteger paramValue)
 {
     foreach (CommonTree f in functionDefinitions)
     {
         // Expected tree for f: ^(FUNC ID (ID | INT) expr)
         if (f.GetChild(0).Text.Equals(name))
         {
             // Check whether parameter matches
             CommonTree formalPar = (CommonTree)f.GetChild(1);
             if (formalPar.Token.Type == INT
                 && !new BigInteger(formalPar.Token.Text).Equals(paramValue))
             {
                 // Constant in formalPar list does not match actual value -> no match.
                 continue;
             }
             // Parameter (value for INT formal arg) as well as fct name agrees!
             return f;
         }
     }
     return null;
 }
Esempio n. 12
0
 /** Find matching function definition for a function name and parameter
  *  value. The first definition is returned where (a) the name matches
  *  and (b) the formal parameter agrees if it is defined as constant.
  */
 private CommonTree findFunction(string name, BigInteger paramValue)
 {
     foreach (CommonTree f in functionDefinitions)
     {
         // Expected tree for f: ^(FUNC ID (ID | INT) expr)
         if (f.GetChild(0).Text.Equals(name))
         {
             // Check whether parameter matches
             CommonTree formalPar = (CommonTree)f.GetChild(1);
             if (formalPar.Token.Type == INT &&
                 !new BigInteger(formalPar.Token.Text).Equals(paramValue))
             {
                 // Constant in formalPar list does not match actual value -> no match.
                 continue;
             }
             // Parameter (value for INT formal arg) as well as fct name agrees!
             return(f);
         }
     }
     return(null);
 }
Esempio n. 13
0
        public byte[] ConvertTo(object value)
        {
            java.math.BigInteger bi = ((java.math.BigDecimal)value).unscaledValue();
            int scale = ((java.math.BigDecimal)value).scale();

            byte[] bibytes = bi.toByteArray();
            byte[] sbytes  = BitConverter.GetBytes(scale);
            Array.Reverse(sbytes);
            byte[] bytes = new byte[bibytes.Length + 4];

            for (int i = 0; i < 4; i++)
            {
                bytes[i] = sbytes[i];
            }

            for (int i = 4; i < bibytes.Length + 4; i++)
            {
                bytes[i] = bibytes[i - 4];
            }

            return(bytes);
        }
Esempio n. 14
0
 public BigInteger(uint uintValue)
 {
     v = java.math.BigInteger.valueOf((long)uintValue);
 }
Esempio n. 15
0
 public BigInteger(long longValue)
 {
     v = java.math.BigInteger.valueOf(longValue);
 }
Esempio n. 16
0
 public BigInteger(float floatValue)
 {
     v = java.math.BigInteger.valueOf((long)(int)floatValue);
 }
Esempio n. 17
0
 public BigInteger(double doubleValue)
 {
     v = java.math.BigInteger.valueOf((long)doubleValue);
 }
Esempio n. 18
0
 private BigInteger(string stringValue)
 {
     v = new java.math.BigInteger(stringValue);
 }