Question

Adding lfsr to the definition of the member function rsa() in the following code give extra qualification error when compiling with gcc 2.8.2. While I see that this 'qualifier' is put in examples mentioned in this page, I don't know why g++ doesn't accept it.

Here is the code:

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <boost/dynamic_bitset.hpp> 

using namespace std;

class lfsr
{
    int y, xx, polyLoc, turnCount, n, end, p, q, d, f, e, m, c, l, g;
    boost::dynamic_bitset<> inpSeq;
    boost::dynamic_bitset<> operSeq;
    boost::dynamic_bitset<> bit;
    vector<int> xorArray;
    vector<int> keyReg;
public:
    lfsr(int, int, int, int, int, int, int,
         int, int, int, int, int, int, int, int,
         boost::dynamic_bitset<>, boost::dynamic_bitset<>, boost::dynamic_bitset<>);

    void rsa(int, int, int, boost::dynamic_bitset<> = boost::dynamic_bitset<>(5));

    int key()
    {
        while (polyLoc > 0)
        {
            xorArray.push_back(polyLoc % 10);
            polyLoc /= 10;
        }
        sort(xorArray.rbegin(), xorArray.rend());
        operSeq = inpSeq;
        keyReg.push_back(inpSeq[0]);
        int x = xorArray[0];

        do {
            for (unsigned int r = 1; r < xorArray.size(); r++)
            {
                bit[4] = operSeq[x];
                y = xorArray[r];
                bit[4] = bit[4] ^ operSeq[y];
            }
            operSeq >>= 1;
            operSeq[4] = bit[4];
            keyReg.push_back(operSeq[0]);
            turnCount++;
        }

        while ((operSeq != inpSeq) && (turnCount < 1024));
        for (unsigned int i = 0; i < keyReg.size(); i++)
        {
            if (keyReg[i] == 1)
            {
                m = m + int(pow(2, i));
            }
            n = p * q;
            f = (p - 1) * (q - 1);
            for (int k = 0; end < 1; k++)
            {
                if ((1 + k * f) % d == 0)
                {
                    end = 2;
                    e = (1 + (k * f)) / d;
                }
            }
            g = int(pow(m, e));
            c = g % n;
            return (c);
        }
    };

    lfsr() // Constructor
    {
        y = 0;
        turnCount = 0;
        xx = 0;
        polyLoc = 320;
        n = 0;
        end = 0;
        p = 0;
        q = 0;
        d = 0;
        f = 0;
        e = 0;
        m = 0;
        c = 0;
        l = 0, g = 0;
        boost::dynamic_bitset<> inpSeq(5);
        boost::dynamic_bitset<> operSeq(5);
        boost::dynamic_bitset<> bit(5);
    }

    void rsa(int x, int y, int z, boost::dynamic_bitset<> initSeq)
    {
        p = x;
        q = y;
        d = z;
        inpSeq = initSeq;
    }

    int main()
    {
        lfsr public_key, private_key;
        public_key.rsa(29, 41, 74, 00111);
        private_key.rsa(43, 89, 73, 01011);
        cout << "Public key is: " << public_key.key() << endl;
        cout << "Private key is: " << private_key.key() << endl;
        cin.get();
        return 0;
    }
Was it helpful?

Solution

Dude. Perhaps you should consider making use of named parameters.

What is the "Named Parameter Idiom" http://www.parashift.com/c++-faq/named-parameter-idiom.html

Or if you use Boost, consider using the following.

The Boost Parameter Library http://www.boost.org/doc/libs/1_55_0/libs/parameter/doc/html/index.html

Or, if you do not like that, a single parameter that is a map of a string to a union (or any, also part of Boost).

All of these would be a better alternative to a constructor with 18 parameters.

Besides, your declared lfsr constructor with 18 parameters, does not match your defined lfsr constructor, with 0, parameters.

By declared, I mean the statement that a function exists, witout code.

lfsr(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, boost::dynamic_bitset<>, boost::dynamic_bitset<>, boost::dynamic_bitset<>);

Is your declared constructor.

By defined, I mean the code.

lfsr()

Is your defined constructor. Of course it should be lfsr::lfsr().

void rsa(int x, int y, int z, boost::dynamic_bitset<> initSeq)

Should be as follows.

void lfsr::rsa(int x, int y, int z, boost::dynamic_bitset<> initSeq)

These clues should be enough to get you started.

OTHER TIPS

Try this:

class lfsr {
   // Constructor declaration
   lfsr();
};

// Constructor definition
lfsr::lfsr() {

}

And I think you are missing a } before your class terminal };.

You should move the whole lfsr() into class lfsr, or declare lfsr(); inside class lfsr before implementing it as

lfsr::lfsr()
{
    //...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top