HEADER_DECLARE Term* Spec(atom_t atom, int size){ FRAME_ENTER; FRAME_LOCAL(tatom) = Atom(atom); FRAME_LOCAL(tsize) = Integer(size); FRAME_RETURN(Term*, Functor2(atom_slash, tatom, tsize)); }
void Dispatcher::getCapabilities (Struct &str) const { // parent::getCapabilities (str); just in case.. str.addMember("specUrl", RpcString("http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php")); str.addMember("specVersion", Integer(20010516)); }
/*}}}*/ void WriteMODM(char *alphabet, ProfileSAD* profile, int numRes, double *parameter, FILE *fpout)/*{{{*/ { int i,j; fprintf(fpout,"#Num: amino acid sequence number\n"); fprintf(fpout,"#AA: 1 letter amino acid\n"); fprintf(fpout,"# profile is derived from log odd score in PSSM file, \n"); fprintf(fpout,"# \n"); int width = 5; fprintf(fpout,"%-5s %-2s","Num","AA"); fprintf(fpout," %3s","SAD"); for(j = 0 ; j < 20 ; j++) fprintf(fpout,"%4c",alphabet[j]); fprintf(fpout, "\n"); for(i = 0 ; i < numRes ; i ++) { fprintf(fpout,"%5d %-2c",i+1,profile[i].aa); fprintf(fpout," %1c%1d%1c",profile[i].shape, profile[i].waterAcc, profile[i].dsspSec); for(j = 0 ; j < 20 ; j++) { fprintf(fpout,"%4d",Integer(profile[i].p[j])); } fprintf(fpout," %4.2f", profile[i].score1); fprintf(fpout," %4.2f", profile[i].score2); fprintf(fpout,"\n"); } fprintf(fpout," K Lambda\n" ); fprintf(fpout,"Standard Ungapped %.4lf %.4lf \n", parameter[0], parameter[1] ); fprintf(fpout,"Standard Gapped %.4lf %.4lf \n", parameter[2], parameter[3] ); fprintf(fpout,"PSI Ungapped %.4lf %.4lf \n", parameter[4], parameter[5] ); fprintf(fpout,"PSI Gapped %.4lf %.4lf \n", parameter[6], parameter[7] ); }
//-------------------------------------------------------------- //LinkableRingSignProver constructor check TEST(LinkableRingSignProverTest, DefaultArgs) { unsigned int n = 100, identity = 12; Integer g_in, p_in, q_in, private_key_in; vector<Integer> public_keys_in; GetGroupParameters(g_in, p_in, q_in); RandomPool rng; //set safe_NO for private key here. Integer SAFE_NO = 1231; //generate private_public keys for(unsigned int i = 1; i <= n; i++) { Integer a = Integer(rng, SAFE_NO, q_in - 1); if(i == 11) private_key_in = a; public_keys_in.push_back(a_exp_b_mod_c(g_in, a, p_in)); } LinkableRingSignProver P(n, identity, g_in, p_in, q_in, public_keys_in, private_key_in); EXPECT_EQ(P.num_members, n); EXPECT_EQ(P.g, g_in); EXPECT_EQ(P.q, q_in); EXPECT_EQ(P.p, p_in); vector<Integer>::iterator itr = public_keys_in.begin(); unsigned int j = 0; for(itr = public_keys_in.begin(); itr != public_keys_in.end(); itr++) { ASSERT_EQ(P.public_keys[j++], *itr); } }
int AsymmCipher::decodeintarray(Integer* t, int numints, const byte* data, int len) { int p, i, n; p = 0; for (i = 0; i < numints; i++) { if (p + 2 > len) { break; } n = ((data[p] << 8) + data[p + 1] + 7) >> 3; p += 2; if (p + n > len) { break; } t[i] = Integer(data + p, n); p += n; } return i == numints && len - p < 16; }
int main(){ std::vector <int > nums ; std::vector < Integer > ints ; for ( int i = 0; i < 10; i++ ) { nums.push_back ( i ); ints.push_back ( Integer ( i ) ); } std::vector <int > nums2 ( nums ); std::ostream_iterator<int> o( std::cout , ", " ); // ptr_fun std::transform ( nums.begin(), nums.end(), o, std::ptr_fun ( plusOne ) ) ; std::cout << std::endl ; // bind Multiplier theMult ; transform(nums.begin(), nums.end(), o, std::bind2nd ( theMult , 10 ) ); std::cout << std::endl ; // mem_fun std::ostream_iterator < Integer > os( std::cout , ", " ); std::for_each ( ints.begin(), ints.end(), std::mem_fun_ref ( & Integer::increment ) ); //i like this one //not1 std::remove_copy_if ( ints.begin(), ints.end(), os, std::not1(std::ptr_fun(checkValid<Integer>))); std::cout << std::endl ; return 0; }
// // VarSys::VarItem::GetStringValue // // Get the string value of a var // const char * VarSys::VarItem::GetStringValue() { static char buff[32]; switch (type) { default: case VarSys::VI_SCOPE: case VarSys::VI_BINARY: ERR_FATAL(("Unsupported type for getting string value")) break; case VarSys::VI_INTEGER: { Utils::Sprintf(buff, 32, "%d", Integer()); return (buff); break; } case VarSys::VI_FPOINT: { Utils::Sprintf(buff, 32, "%f", Float()); return (buff); break; } case VarSys::VI_STRING: { return (Str()); break; } } }
std::ostream& operator<<(std::ostream& out, Month m) { switch (m) { case January: return out << "January"; case February: return out << "February"; case March: return out << "March"; case April: return out << "April"; case May: return out << "May"; case June: return out << "June"; case July: return out << "July"; case August: return out << "August"; case September: return out << "September"; case October: return out << "October"; case November: return out << "November"; case December: return out << "December"; default: QL_FAIL("unknown month (" << Integer(m) << ")"); } }
void PrimeSieve::DoSieve() { unsigned int primeTableSize; const word16 * primeTable = GetPrimeTable(primeTableSize); const unsigned int maxSieveSize = 32768; unsigned int sieveSize = STDMIN(Integer(maxSieveSize), (m_last-m_first)/m_step+1).ConvertToLong(); m_sieve.clear(); m_sieve.resize(sieveSize, false); if (m_delta == 0) { for (unsigned int i = 0; i < primeTableSize; ++i) SieveSingle(m_sieve, primeTable[i], m_first, m_step, (word16)m_step.InverseMod(primeTable[i])); } else { assert(m_step%2==0); Integer qFirst = (m_first-m_delta) >> 1; Integer halfStep = m_step >> 1; for (unsigned int i = 0; i < primeTableSize; ++i) { word16 p = primeTable[i]; word16 stepInv = (word16)m_step.InverseMod(p); SieveSingle(m_sieve, p, m_first, m_step, stepInv); word16 halfStepInv = 2*stepInv < p ? 2*stepInv : 2*stepInv-p; SieveSingle(m_sieve, p, qFirst, halfStep, halfStepInv); } } }
template <typename Integer> static bool isPrime(Integer N){ Integer M = sqrt(N)+1; for(Integer i = 2; i < M; i = i+Integer(1)){ if (N%i == 0) return false; } return true; }
Array DifferentialEvolution::getMutationProbabilities( const std::vector<Candidate> & population) const { Array mutationProbabilities = currGenCrossover_; switch (configuration().crossoverType) { case Normal: break; case Binomial: mutationProbabilities = currGenCrossover_ * (1.0 - 1.0 / population.front().values.size()) + 1.0 / population.front().values.size(); break; case Exponential: for (Size coIter = 0;coIter< currGenCrossover_.size(); coIter++){ mutationProbabilities[coIter] = (1.0 - std::pow(currGenCrossover_[coIter], (int) population.front().values.size())) / (population.front().values.size() * (1.0 - currGenCrossover_[coIter])); } break; default: QL_FAIL("Unknown crossover type (" << Integer(configuration().crossoverType) << ")"); break; } return mutationProbabilities; }
const Integer Integer::negate() const { std::string temp = this->bytes; if (this->positive) { temp.insert(0, "-"); } return Integer(temp); }
std::ostream& operator<<(std::ostream& out, const short_period_holder& holder) { Integer n = holder.p.length(); Integer m = 0; switch (holder.p.units()) { case Days: if (n>=7) { m = n/7; out << m << "W"; n = n%7; } if (n != 0 || m == 0) return out << n << "D"; else return out; case Weeks: return out << n << "W"; case Months: if (n>=12) { m = n/12; out << n/12 << "Y"; n = n%12; } if (n != 0 || m == 0) return out << n << "M"; else return out; case Years: return out << n << "Y"; default: QL_FAIL("unknown time unit (" << Integer(holder.p.units()) << ")"); } }
std::ostream& operator<<(std::ostream& out, const long_period_holder& holder) { Integer n = holder.p.length(); Integer m = 0; switch (holder.p.units()) { case Days: if (n>=7) { m = n/7; out << m << (m == 1 ? " week " : " weeks "); n = n%7; } if (n != 0 || m == 0) return out << n << (n == 1 ? " day" : " days"); else return out; case Weeks: return out << n << (n == 1 ? " week" : " weeks"); case Months: if (n>=12) { m = n/12; out << m << (m == 1 ? " year " : " years "); n = n%12; } if (n != 0 || m == 0) return out << n << (n == 1 ? " month" : " months"); else return out; case Years: return out << n << (n == 1 ? " year" : " years"); default: QL_FAIL("unknown time unit (" << Integer(holder.p.units()) << ")"); } }
void * reduce_phase2(const void * _exp) { if(isA(_exp, Integer())) return domainCast(_exp, Real()); else if(isA(_exp, Real()) || isA(_exp, Var())) return copy(_exp); else if(isA(_exp, Sum()) || isA(_exp, Product())) { void * s = copy(_exp); size_t i; for(i = 0; i < size(s); ++i) { delete(argv(s, i)); setArgv(s, i, reduce_phase2(argv(_exp, i))); } return s; } else if(isA(_exp, Pow())) { void * p = copy(_exp); delete(base(p)); delete(power(p)); setBase(p, reduce_phase2(base(_exp))); setPower(p, reduce_phase2(power(_exp))); return p; } else if(isOf(_exp, Apply_1())) { void * f = copy(_exp); delete(arg(f)); setArg(f, reduce_phase2(arg(_exp))); return f; } assert(0); }
virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const { TestData::const_iterator i = m_data.find(name); if (i == m_data.end()) return false; const std::string &value = i->second; if (valueType == typeid(int)) *reinterpret_cast<int *>(pValue) = atoi(value.c_str()); else if (valueType == typeid(Integer)) *reinterpret_cast<Integer *>(pValue) = Integer((std::string(value) + "h").c_str()); else if (valueType == typeid(ConstByteArrayParameter)) { m_temp.resize(0); PutDecodedDatumInto(m_data, name, StringSink(m_temp).Ref()); reinterpret_cast<ConstByteArrayParameter *>(pValue)->Assign((const byte *)m_temp.data(), m_temp.size(), true); } else if (valueType == typeid(const byte *)) { m_temp.resize(0); PutDecodedDatumInto(m_data, name, StringSink(m_temp).Ref()); *reinterpret_cast<const byte * *>(pValue) = (const byte *)m_temp.data(); } else throw ValueTypeMismatch(name, typeid(std::string), valueType); return true; }
void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) { int modulusSize = 2048; alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); ASSERT( modulusSize >= 16 ); m_e = alg.GetValueWithDefault("PublicExponent", Integer(17)); ASSERT( m_e >= 3 ); ASSERT( !m_e.IsEven() ); RSAPrimeSelector selector(m_e); const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) ("PointerToPrimeSelector", selector.GetSelectorPointer()); m_p.GenerateRandom(rng, primeParam); m_q.GenerateRandom(rng, primeParam); m_d = EuclideanMultiplicativeInverse(m_e, LCM(m_p-1, m_q-1)); assert(m_d.IsPositive()); m_dp = m_d % (m_p-1); m_dq = m_d % (m_q-1); m_n = m_p * m_q; m_u = m_q.InverseMod(m_p); }
bool LRSPublicKey::Verify(const QByteArray &data, const LRSSignature &sig) const { if(!sig.IsValid()) { qDebug() << "Invalid signature"; return false; } if(sig.SignatureCount() != GetKeys().count()) { qDebug() << "Incorrect amount of keys used to generate signature."; return false; } CppHash hash; hash.Update(GetGroupGenerator().GetByteArray()); hash.Update(sig.GetTag().GetByteArray()); hash.Update(data); QByteArray precompute = hash.ComputeHash(); Integer tcommit = sig.GetCommit1(); QVector<Integer> keys = GetKeys(); for(int idx = 0; idx < keys.count(); idx++) { Integer z_p = (GetGenerator().Pow(sig.GetSignature(idx), GetModulus()) * _keys[idx].Pow(tcommit, GetModulus())) % GetModulus(); Integer z_pp = (GetGroupGenerator().Pow(sig.GetSignature(idx), GetModulus()) * sig.GetTag().Pow(tcommit, GetModulus())) % GetModulus(); hash.Update(precompute); hash.Update(z_p.GetByteArray()); hash.Update(z_pp.GetByteArray()); tcommit = Integer(hash.ComputeHash()) % GetSubgroup(); } return tcommit == sig.GetCommit1(); }
std::ostream& operator<<(std::ostream& out, Frequency f) { switch (f) { case NoFrequency: return out << "No-Frequency"; case Once: return out << "Once"; case Annual: return out << "Annual"; case Semiannual: return out << "Semiannual"; case EveryFourthMonth: return out << "Every-Fourth-Month"; case Quarterly: return out << "Quarterly"; case Bimonthly: return out << "Bimonthly"; case Monthly: return out << "Monthly"; case EveryFourthWeek: return out << "Every-fourth-week"; case Biweekly: return out << "Biweekly"; case Weekly: return out << "Weekly"; case Daily: return out << "Daily"; case OtherFrequency: return out << "Unknown frequency"; default: QL_FAIL("unknown frequency (" << Integer(f) << ")"); } }
FixedRateBond::FixedRateBond(Natural settlementDays, const Calendar& calendar, Real faceAmount, const Date& startDate, const Date& maturityDate, const Period& tenor, const std::vector<Rate>& coupons, const DayCounter& accrualDayCounter, BusinessDayConvention accrualConvention, BusinessDayConvention paymentConvention, Real redemption, const Date& issueDate, const Date& stubDate, DateGeneration::Rule rule, bool endOfMonth, const Calendar& paymentCalendar) : Bond(settlementDays, paymentCalendar==Calendar() ? calendar : paymentCalendar, issueDate), frequency_(tenor.frequency()), dayCounter_(accrualDayCounter) { maturityDate_ = maturityDate; Date firstDate, nextToLastDate; switch (rule) { case DateGeneration::Backward: firstDate = Date(); nextToLastDate = stubDate; break; case DateGeneration::Forward: firstDate = stubDate; nextToLastDate = Date(); break; case DateGeneration::Zero: case DateGeneration::ThirdWednesday: case DateGeneration::Twentieth: case DateGeneration::TwentiethIMM: QL_FAIL("stub date (" << stubDate << ") not allowed with " << rule << " DateGeneration::Rule"); default: QL_FAIL("unknown DateGeneration::Rule (" << Integer(rule) << ")"); } Schedule schedule(startDate, maturityDate_, tenor, calendar, accrualConvention, accrualConvention, rule, endOfMonth, firstDate, nextToLastDate); cashflows_ = FixedRateLeg(schedule) .withNotionals(faceAmount) .withCouponRates(coupons, accrualDayCounter) .withPaymentCalendar(calendar_) .withPaymentAdjustment(paymentConvention); addRedemptionsToCashflows(std::vector<Real>(1, redemption)); QL_ENSURE(!cashflows().empty(), "bond with no cashflows!"); QL_ENSURE(redemptions_.size() == 1, "multiple redemptions created"); }
int32_t Integer::operator < (const int64_t l) const { #if GMP_LIMB_BITS != 64 return mpz_cmp_si((mpz_srcptr)&gmp_rep, l) < 0; #else return this->operator < (Integer(l)); #endif }
// generate a random private key InvertibleRabinFunction::InvertibleRabinFunction(RandomNumberGenerator &rng, unsigned int keybits) { assert(keybits >= 16); // generate 2 random primes of suitable size if (keybits%2==0) { const Integer minP = Integer(182) << (keybits/2-8); const Integer maxP = Integer::Power2(keybits/2)-1; p.Randomize(rng, minP, maxP, Integer::PRIME, 3, 4); q.Randomize(rng, minP, maxP, Integer::PRIME, 3, 4); } else { const Integer minP = Integer::Power2((keybits-1)/2); const Integer maxP = Integer(181) << ((keybits+1)/2-8); p.Randomize(rng, minP, maxP, Integer::PRIME, 3, 4); q.Randomize(rng, minP, maxP, Integer::PRIME, 3, 4); } bool rFound=false, sFound=false; Integer t=2; while (!(rFound && sFound)) { int jp = Jacobi(t, p); int jq = Jacobi(t, q); if (!rFound && jp==1 && jq==-1) { r = t; rFound = true; } if (!sFound && jp==-1 && jq==1) { s = t; sFound = true; } ++t; } n = p * q; assert(n.BitCount() == keybits); u = EuclideanMultiplicativeInverse(q, p); assert(u*q%p==1); }
Element ByteGroup::Exponentiate(const Element &a, const Integer &exp) const { if((exp % Integer(2)) == 0) { return GetIdentity(); } else { return a; } }
void EncryptorTemplate<P,F>::Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) { assert(plainTextLength <= MaxPlainTextLength()); SecByteBlock paddedBlock(PaddedBlockByteLength()); pad.Pad(rng, plainText, plainTextLength, paddedBlock, PaddedBlockBitLength()); f.ApplyFunction(Integer(paddedBlock, paddedBlock.size)).Encode(cipherText, CipherTextLength()); }
void DigestSignerTemplate<P,F>::SignDigest(RandomNumberGenerator &rng, const byte *digest, unsigned int digestLength, byte *signature) const { assert(digestLength <= MaxDigestLength()); SecByteBlock paddedBlock(PaddedBlockByteLength()); pad.Pad(rng, digest, digestLength, paddedBlock, PaddedBlockBitLength()); f.CalculateInverse(Integer(paddedBlock, paddedBlock.size)).Encode(signature, DigestSignatureLength()); }
bool DigestVerifierTemplate<P,F>::VerifyDigest(const byte *digest, unsigned int digestLen, const byte *signature) const { SecByteBlock paddedBlock(PaddedBlockByteLength()); f.ApplyFunction(Integer(signature, DigestSignatureLength())).Encode(paddedBlock, paddedBlock.size); SecByteBlock recoveredDigest(MaxDigestLength()); unsigned int recoveredDigestLen = pad.Unpad(paddedBlock, PaddedBlockBitLength(), recoveredDigest); return digestLen == recoveredDigestLen && memcmp(digest, recoveredDigest, digestLen) == 0; }
Opnd opnd_immed(int value, TypeId type) { OpndImmedInteger *obj = create_opnd_immed_integer(the_suif_env, type, Integer(value)); the_local_scope->append_symbol_table_object(obj); return obj; }
Integer Integer::operator + (const uint64_t l) const { if (l==0) return *this; if (isZero(*this)) return Integer(l); Integer res; mpz_add_ui( (mpz_ptr)&(res.gmp_rep), (mpz_srcptr)&gmp_rep, l); return res; }
void __fastcall TfrmBarsNotepadMain::liZoomClick(TObject *Sender) { if (FUpdatingControls == 0) { Editor->Properties->ZoomFactor = double (Integer(liZoom->Items->Objects[liZoom->ItemIndex])) / 100; UpdateControls(); } }
int32_t absCompare(const Integer &a, const int64_t b) { #if GMP_LIMB_BITS != 64 return absCompare( a, Integer(b)); #else return mpz_cmpabs_ui( (mpz_srcptr)&(a.gmp_rep), (uint64_t) std::abs(b)); #endif }