def testObjectArgument(): f = Foo() base = BigInteger.valueOf(12) result = base.multiply(BigInteger.valueOf(2)) eq_(result.longValue(), f.doubleIt(base)) eq_(result, Reflector.call(f, "doubleIt", [Number], [base])) eq_(len(Reflector.getExceptionTypes(f.getClass(), "doubleIt", [Number])), 2)
def testObjectArgument(): f = Foo() base = BigInteger.valueOf(12) result = base.multiply(BigInteger.valueOf(2)) eq_(result, f.doubleIt(base)) eq_(result, Reflector.call(f, "doubleIt", [Number], [base])) #XXX: getting to the IFoo interface this way is brittle. iface = f.__class__.__base__.__bases__[0] excepts = Reflector.getExceptionTypes(iface, "doubleIt", [Number]) eq_(len(excepts), 2)
def testObjectArgument(): f = Foo() base = BigInteger.valueOf(12) result = base.multiply(BigInteger.valueOf(2)) eq_(result , f.doubleIt(base)) eq_(result, Reflector.call(f, "doubleIt", [Number], [base])) #XXX: getting to the IFoo interface this way is brittle. iface = f.__class__.__base__.__bases__[0] excepts = Reflector.getExceptionTypes(iface, "doubleIt", [Number]) eq_(len(excepts), 2)
def sympyRat2jBigIntegerPair(val): numer = val.p # numerator if numer.bit_length() <= 63: numer = BigInteger.valueOf(numer) else: numer = BigInteger(str(numer)) denom = val.q # denominator if denom.bit_length() <= 63: denom = BigInteger.valueOf(denom) else: denom = BigInteger(str(denom)) return (numer, denom)
def _myTurn(self): if self.lastReceivedBid != None and self.profile.getProfile().getUtility(self.lastReceivedBid).doubleValue() > 0.6: action = Accept(self.me, self.lastReceivedBid) else: bidspace = AllPartialBidsList(self.profile.getProfile().getDomain()) bid = None for attempt in range(20): i = self.random.nextInt(bidspace.size()) # warning: jython implicitly converts BigInteger to long. bid = bidspace.get(BigInteger.valueOf(i)) if self._isGood(bid): break action = Offer(self.me, bid); try: self.getConnection().send(action) except: print 'failed to send action '+action.toString() traceback.print_exc()
def keyGenerating(primeBit, A): myPK = [0, 0, 0] batasBawah = pow(2, (primeBit - 1)) up = primeBit batasAtas = (pow(2, up)) batasAtas = batasAtas - 1 prime = randint(batasBawah, batasAtas) prime = nonExshaustingPrimeGenerator.valueOf(prime) #prime = nonExshaustingPrimeGenerator.nextProbablePrime(prime) while (primality.pengujianMSR(prime) == False): prime = nonExshaustingPrimeGenerator.nextProbablePrime( prime) #randint(batasBawah, batasAtas) prime = int(prime) alpha = primitiveRoot.GaussForPrimitiveRoot(prime) alpha_a = pow(alpha, A) alpha_a = alpha_a % prime myPK[0] = alpha myPK[1] = alpha_a myPK[2] = prime return myPK
print 'N: %s' % N one = BigInteger("1") Euler = P.subtract(one).multiply(Q.subtract(one)) print 'Euler: %s' % Euler E = BigInteger("17") print 'E: %s' % E try: D = E.modInverse(Euler) print 'D: %s' % D except ArithmeticException: print >>sys.stderr, 'Failed. E is not invertible' sys.exit(1) msg = 'A test message' print 'Original message: %s' % msg result = [] for ch in msg: result.append(BigInteger.valueOf(ord(ch)).modPow(E, N)) print 'Encrypted: %s' % result decrypted = '' for el in result: decrypted += chr(BigInteger(str(el)).modPow(D, N).intValue()) print 'Decrypted: %s' % decrypted
from crcl.base import * from crcl.utils import CRCLSocket from crcl.utils import CRCLPosemath from java.math import BigInteger from java.math import BigDecimal import java.lang.Boolean print "Connect" s = CRCLSocket("localhost", 64444) #s.setEXIEnabled(True) instance = CRCLCommandInstanceType() ## Create and send InitCanon command print "Send InitCanon" init = InitCanonType() init.setCommandID(BigInteger.valueOf(7)) instance.setCRCLCommand(init) s.writeCommand(instance) # ## Create and send MoveTo command. print "Send MoveTo" moveTo = MoveToType() moveTo.setCommandID(BigInteger.valueOf(8)) pt = CRCLPosemath.point(0.6,0.1,0.1) xaxis = CRCLPosemath.vector(1.0,0.0,0.0) zaxis = CRCLPosemath.vector(0.0,0.0,1.0) pose = CRCLPosemath.pose(pt,xaxis,zaxis) moveTo.setEndPosition(pose) moveTo.setMoveStraight(java.lang.Boolean.FALSE) instance.setCRCLCommand(moveTo) s.writeCommand(instance)
public static void calcularFactorial(int numero){ int contador=1; long resultado=1; if(numero>1){resultado=numero;} while(contador<numero){ resultado=resultado*contador; contador++; } System.out.println("El factorial de "+numero+" es "+resultado+""); } public static void calcularFactorialBig(int numero) { int contador=1; BigInteger resultado=BigInteger.valueOf(1); if(numero>1){resultado=BigInteger.valueOf(numero);} while(contador<numero){ resultado=resultado.multiply(BigInteger.valueOf(contador)); contador++; } System.out.println("El factorial de "+numero+" es "+resultado+""); } public static void rangoFactorial(int numfinal) { for(int inicio=0;inicio<=numfinal;inicio++){ calcularFactorialBig(inicio); } }
loadExports(memBlock) elif structsize == 0x2C: loadImports(memBlock) entry_point = memory.getLong(memory.getBlocks()[0].getStart().add(0x18)) print "%x" % entry_point opd_sect = memory.getBlock(toAddr(entry_point)) addr = opd_sect.getStart() while addr < opd_sect.getEnd(): func_ptr = toAddr(memory.getInt(addr)) func_toc = memory.getInt(addr.add(0x4)) createFunction(func_ptr, None) func = getFunctionAt(func_ptr) func_min = func.getBody().getMinAddress() func_max = func.getBody().getMaxAddress() try: createDWord(addr) except: pass try: createDWord(addr.add(0x4)) except: pass r2reg = currentProgram.getRegister("r2") tocValue = RegisterValue(r2reg, BigInteger.valueOf(func_toc)) currentProgram.getProgramContext().setRegisterValue( func_min, func_max, tocValue) addr = addr.add(0x18)
def int2jBigInteger(val): if val.bit_length() <= 63: return BigInteger.valueOf(val) else: return BigInteger(str(val))