Pollard Rho is an earlier precursor to more advanced algorithms such as the Quadratic Sieve and Generalized Number Field Sieve. It has limitations on factoring 96 bit semi-primes, although it maybe able to factor larger numbers provided they are not semi-primes. A semi-prime is a number whose factors are two unique primes. These numbers play a significant role in modern cryptography algorithms such as the RSA algorithm.

The main function of Pollard Rho as implemented in our int_t class looks like the following:

/* Copyright (c) 2017 ObjectSoftware.biz. All rights reserved. Presented under GPL v2. */ int_t rho(int_t N) { int_t divisor; int_t c = N.getRand(N.getBitLength(N)); int_t x = N.getRand(N.getBitLength(N)); int_t xx = x; // check divisibility by 2 if ((N % int_t::TWO) == int_t::ZERO) return int_t::TWO; do { x = ((((x * x) % N) + c) % N); xx = ((((xx * xx) % N) + c) % N); xx = ((((xx * xx) % N) + c) % N); divisor = (x - xx).gcd(N); } while(divisor == int_t::ONE); return divisor; }

Notice that we have implemented the gcd algorithm as well as most operators within the int_t class and this allows for the calculation to be implemented almost as if it was using a built-in type. Because int_t uses GMP underneath, the code is arbitrary precise. However, there are limitations in what can be computed in a reasonable time frame. The Pollard Rho algorithm works by selecting an integer for which the gcd with N is not one. And by doing so, it finds a factoring. Since this non-deterministic, its possible that the algorithm doesn’t find a factoring, or takes too long to find a factoring if N is large (since the factors would also be large and infrequently occurring in a number sequence.

Once we have a factoring, we can apply the definition of Euler Phi to compute the Totient function of N. The following is the code:

/* Copyright (c) 2017 ObjectSoftware.biz. All rights reserved. Presented under GPL v2. */ int_t phi(int_t n) { mpf_t rtvl, one, fraction, sub; mpf_init(rtvl); mpf_init(one); mpf_init(fraction); mpf_init(sub); mpf_set_ui(rtvl,1); mpf_set_ui(one, 1); mpf_set_ui(sub, 0); set uniq; for(list::iterator i = factors.begin(); i != factors.end(); ++i) { if(uniq.find((*i)) == uniq.end()) { uniq.insert((*i)); } } for(set::iterator i = uniq.begin(); i != uniq.end(); ++i) { mpf_t tmp; mpf_init(tmp); const char *str = (*i).toString().c_str(); mpf_set_str(tmp,str,10); mpf_div(fraction,one,tmp); mpf_sub(sub,one,fraction); mpf_mul(rtvl,rtvl,sub); mpf_clear(tmp); } mp_exp_t exp; char *tmp = new char[4096]; gmp_sprintf(tmp,"%.Ff",rtvl); int_t r = compute(tmp,n); delete[] tmp; mpf_clear(rtvl); mpf_clear(one); mpf_clear(sub); mpf_clear(fraction); return r; }

The Euler Phi algorithm above is:

Given a factoring of n

select uniq prime factors.

Then compute the product of 1-1/prime

for all prime factors of N, and

multiply the ratio by N.

The end result is Euler Phi

Notice that it is possible to factor N given Euler Phi of N; however, computing Euler Phi should be clear is as difficult as factoring N. Thus, one can not break algorithms such as RSA simply by computing Euler Phi of the modulus and applying the quadratic equation to solve because this is as hard as factoring N directly. Note that the above implementation of Euler Phi is much faster than the one given using trial division as Pollard Rho is faster than trial division for N up to about 96 bits, and subsequently calculating Euler Phi from N’s factors is faster than simply counting factors for N.

Please write to us for a complete implementation of the above. Thanks

]]>The basic syntax of this class is:

#include "int.h" int main() { int_t i("2"); i++; i.print(stdout); return 0; }

The full implementation of this class is as follows:

(int_t.h)

/* Copyright (C) 2017, ObjectSoftware.biz, All Rights Reserved. * Presented under the GPL v2 license. */ #ifndef _INT_T_H #define _INT_T_H #include #include #include #include #include #include #include using std::string; class int_t { public: mpz_t mp; int_t(const char *n) { mpz_init(mp); mpz_set_str(mp,n,10); } int_t() { mpz_init(mp); mpz_set_str(mp,"0",10); } int_t(mpz_t n) { mpz_init(mp); mpz_set(mp,n); } int_t(double n) { unsigned long i = (unsigned long long)n; mpz_init(mp); mpz_set_ui(mp,i); } int_t(int n) { mpz_init(mp); mpz_set_ui(mp,n); } ~int_t() { mpz_clear(mp); } int_t &operator=(const int_t n) { if(this != &n) { mpz_set(mp,n.mp); } return *this; } int_t(const int_t &n) { mpz_init(mp); mpz_set(mp,n.mp); } mpz_t *getMpz() { return ∓ } int_t gcd(int_t &n) { int_t rtvl = ZERO; mpz_gcd(rtvl.mp,mp,n.mp); return rtvl; } bool operator<=(const int_t n) const { if(*this < n || *this == n) { return true; } else { return false; } } bool operator==(const int_t n) const { if(mpz_cmp(mp,n.mp) == 0) { return true; } else { return false; } } bool operator!=(const int_t n) const { if(mpz_cmp(mp,n.mp) != 0) { return true; } else { return false; } } bool operator<(const int_t n) const { if(mpz_cmp(mp,n.mp) < 0) { return true; } else { return false; } } bool operator>(const int_t n) const { if(mpz_cmp(mp,n.mp) > 0) { return true; } else { return false; } } int_t operator-(const int_t n) const { int_t rtvl = ZERO; mpz_sub(rtvl.mp,mp,n.mp); return rtvl; } int_t operator+(const int_t n) const { int_t rtvl = ZERO; mpz_add(rtvl.mp,mp,n.mp); return rtvl; } int_t operator/(const int_t n) const { int_t rtvl = ZERO; mpz_div(rtvl.mp,mp,n.mp); return rtvl; } int_t operator*(const int_t n) const { int_t rtvl = ZERO; mpz_mul(rtvl.mp,mp,n.mp); return rtvl; } int_t operator%(const int_t n) const { int_t rtvl = ZERO; mpz_mod(rtvl.mp,mp,n.mp); return rtvl; } int_t operator*=(const int_t n) { int_t rtvl = ZERO; mpz_mul(rtvl.mp,mp,n.mp); mpz_set(mp,rtvl.mp); return rtvl; } int_t operator++(int) { int_t tmp = *this; *this = *this + ONE; return tmp; } int_t operator--(int) { int_t tmp = *this; *this = *this - ONE; return tmp; } int_t modExp(int_t base, int_t exp, int_t mod) { int_t rtvl; mpz_powm(rtvl.mp,base.mp,exp.mp,mod.mp); return rtvl; } int_t exp(int_t base, unsigned long e) { int_t rtvl; mpz_pow_ui(rtvl.mp,base.mp,e); return rtvl; } unsigned long toInt() { return mpz_get_ui(mp); } double toDouble() { string n = toString(); double rtvl = 0.0; rtvl = strtod(n.c_str(),NULL); return rtvl; } string toString() const { int bits = getBitLength(*this); char *str = new char[bits + 1]; mpz_get_str(str,10,mp); string rtvl = str; delete[] str; return rtvl; } bool isPerfectPower() { return mpz_perfect_power_p(mp) != 0; } void print(FILE *out) { mpz_out_str(out,10,mp); fprintf(out,"\n"); } int_t getRand(int bits) { static mpz_t rand_Num; unsigned long int i, seed; gmp_randstate_t r_state; seed = time(0); gmp_randinit_default (r_state); gmp_randseed_ui(r_state, seed); mpz_init(rand_Num); mpz_urandomb(rand_Num,r_state,bits); gmp_randclear(r_state); return int_t(rand_Num); } int getBitLength(int_t n) const { int_t x=TWO; int count = 1; while(x < n) { x *= TWO; count++; } return count; } bool isProbPrime() { if (mpz_probab_prime_p(mp,20)) { return true; } else { return false; } } double inverse(double i) { double n = toInt(); return i / n; } int_t sqrt() { int_t rtvl; if(*this < int_t::ONE) { return int_t::ZERO; } mpz_sqrt(rtvl.mp,this->mp); return rtvl; } static int_t ZERO; static int_t ONE; static int_t TWO; static int_t THREE; static int_t FOUR; static int_t FIVE; static int_t SIX; static int_t SEVEN; static int_t EIGHT; static int_t NINE; static int_t TEN; }; #endif

And for the C++ source file, int_t.cc:

/* Copyright (C) 2017, ObjectSoftware.biz, All Rights Reserved. * Presented under the GPL v2 license. */ #include "int_t.h" int_t int_t::ZERO = "0"; int_t int_t::ONE = "1"; int_t int_t::TWO = "2"; int_t int_t::THREE = "3"; int_t int_t::FOUR = "4"; int_t int_t::FIVE = "5"; int_t int_t::SIX = "6"; int_t int_t::SEVEN = "7"; int_t int_t::EIGHT = "8"; int_t int_t::NINE = "9"; int_t int_t::TEN ="10";

Additional posts will discuss some algorithms that we can build using this class.

]]>There is a major problem with this approach, and that is its limited in the size of the array needed to keep track of the integers. A simple way to implement the sieve without using an array buffer to track the integers follows:

/* Copyright (C) 2017, ObjectSoftware.biz, All Rights Reserved. * Presented under the GPL v2 license. */ #include "int.h" typedef list<int_t> list_t; list_t seive(int_t limit) { list_t primes; primes.push_back("2"); for(int_t i = int_t::THREE; i < limit; i++) { int_t sqrt = i.sqrt(); for(list_t::iterator j = primes.begin(); j != primes.end(); j++) { if((*j) > sqrt) { goto IS_PRIME; } if((i % (*j)) == int_t::ZERO) { goto IS_COMPOSITE; } } IS_PRIME: primes.push_back(i); i.print(stdout); IS_COMPOSITE: /* no-op */; } return primes; }

The above implementation assumes an arbitrary precise integer class called int_t which we will discuss in another post. Suffice it to say that the class uses GMP for integer and floating point calculations and is just a simple wrapper in C++.

Notice that the algorithm uses the discovered primes to verify if the next number is prime and proceeds to build a list of primes without keeping track of all integers the way the classic sieve does. The algorithm was used to generate the first 32 bit primes.

]]>While this may be sufficient for scientific calculations, consider financial applications. Two problems such as tolerance in a brokerages assignment of positions to funds, and Quantitative calculations that aim to decide pricing of securities and derivatives. Under these circumstances, an institution may not want an approximation of a Floating Point value since such a value would represent money.

To remedy this situation, we designed Multi Arbitrary Precision library to implement arbitrary precise Floating Point using an integer value and a mantissa value. This way, there is no loss of precision and one can compare Floating Point numbers directly. In fact, our library provides drop-in replacements of built-in integer and float types to ease the migration. Consider using Multi for your next FinTech project.

]]>One suggestion, is that prominent minorities, such as those Actors, Musicians and Athletes, should partner with colleges and engineering professionals to create new Venture Capital groups that can hopefully review and fund business plans of minority candidates. I am certain there are many ideas that are yet to be implemented, and many inventions that still need to be discovered. Since simply pointing out the discrepancies among those business plans that have been funded and those that have not, doesn’t seem to be improving the situation. One has to clearly choose a path of independence and hopefully people can come together to create new ventures.

Another suggestion, is for those who are minority candidates in Computer Science/STEM fields, to work towards creating their own businesses outside of the Venture Capital community. There are many courses designed to educate people on how to create an online business with little to no money to start, and certainly web technology is now more accessible then ever. Why not take the chance and create a web business on the side? Consider that web hosting is very inexpensive, with plans costing just a few dollars a month. Additionally, WordPress and OpenCart are free and can be utilized to create a site with just point and click (instead of coding). The key of course is attracting quality leads and being able to market to them and get conversions, but this is not that hard with SEO plugins available and websites that sell solo-ads providing clicks for just 35 cents per click. Further, there are several free/inexpensive tools/sites that can be used to generate landing pages and integrations with automated email marketing solutions.

You will notice that the potential solutions I mentioned do not include actually trying to change the existing Venture Capital system for the better. The reason is I believe its a lost cause to go to the very people who are excluding minorities from Venture Capital, and expect a different result. Especially when many of them have openly stated they only want to fund people who look like Mark Z. So the next best thing is for all of us who are in Computer Science/STEM, but do not necessarily fit the image of the status quo, strive to create our own Venture Capital Funds and our own corporations.

We at ObjectSoftware.biz are firmly committed to Diversity in technology.

]]>ezSQL is a client/server system consisting of client and server executables, in addition to dynamic link libraries for providing access to the client and server. It provides two primary interfaces:

For C/C++ server access:

result_set *sql_run(const char *sql_statement, const char *login);

And for C/C++ client access:

result_set *sql_client( int argc, char ** argv , bool output = false);

Both interfaces communicate to the SQL back end. The sql_run API can be linked to provide direct access to the back end, and the sql_client API allows access over TCP/IP and requires the sql.exe server to be running.

Once a request is sent over to the server via either API, the server performs the request and returns back the results in the result_set data structure. This allows a simple and clean interface for enabling common SQL features in the application.

For more information, please sign-up to receive our white paper.

]]>