0

The following declaration of the function gives an error at compiling with g++:

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

The error is: expected ‘,’ or ‘...’ before ‘(’ token

And here is the whole 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:
    void rsa(int, int, int, boost::dynamic_bitset<>);
    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 lfsr::rsa(int x, int y, int z, boost::dynamic_bitset<> initSeq(5))
    {
        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;
    }
David G
  • 94,763
  • 41
  • 167
  • 253
Mohamed Ahmed
  • 457
  • 1
  • 7
  • 25
  • 2
    `boost::dynamic_bitset <> initSeq(5)` as a function parameter is simply not valid syntax. – chris May 09 '14 at 23:12
  • What is the valid syntax, please? – Mohamed Ahmed May 09 '14 at 23:13
  • For what, a [default argument](http://en.cppreference.com/w/cpp/language/default_arguments)? You should also be aware that literals starting with 0 are octal literals. I'm not overly sure if that's what you wanted. – chris May 09 '14 at 23:14
  • Sorry, I don't understand well what you are saying. I am trying to declare a variable to take 3 integers and a dynamic bitset of size 5. What literals are you referring to? – Mohamed Ahmed May 09 '14 at 23:17
  • remove that "(5)", use a reference or whatever suits you better – Marco A. May 09 '14 at 23:20
  • So you just want to make sure that the bitset that's coming in has a size of 5? How about `if (initSeq.size() != 5) {/*error*/}`? And the literals I'm talking about are the `00111` and `01011`, which have the values 73 and 265 respectively. – chris May 09 '14 at 23:21
  • @Marco What is a reference?! – Mohamed Ahmed May 09 '14 at 23:25
  • @MohamedAhmed This does not look good – Marco A. May 09 '14 at 23:26
  • What is it that doesn't look good?! – Mohamed Ahmed May 09 '14 at 23:27
  • @MohamedAhmed, It's really looking like you should acquire a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – chris May 09 '14 at 23:28
  • Yes, I am a novice coder. I have been given this link before today :) Thanks to you both for baring with me. – Mohamed Ahmed May 09 '14 at 23:30

1 Answers1

0

Change this code

lfsr() //Constructor

into

lfsr::lfsr() //Constructor

And insert the declaration of constructor into your class

class lfsr {
    ....
public:
    lfsr();
    ....

And move default argument of initSeq1 from definition to declaration. (There it must be in declaration.)

Moreover, your default argument is wrong. It should be initSeq = boost::dynamic_bitset<>(5)

Change this code

class lfsr {
    ....
public:
    void rsa (int, int, int, boost::dynamic_bitset <>);
    ....
};
void lfsr::rsa (int x, int y, int z, boost::dynamic_bitset <> initSeq(5))
{
    ...

into

class lfsr {
    ....
public:
    void rsa (int, int, int, boost::dynamic_bitset<> = boost::dynamic_bitset<>(5));
    ....
};
void lfsr::rsa (int x, int y, int z, boost::dynamic_bitset<> initSeq)
{
    ...
ikh
  • 10,119
  • 1
  • 31
  • 70
  • About inserting the declaration of the constructor to my class, that means that I have to write 15 empty ints inside the parentheses of lsfrs(), and 3 boost::dyanmic bitsets? – Mohamed Ahmed May 09 '14 at 23:55
  • @MohamedAhmed Maybe no.. Doesn't your constructor have no arguments? – ikh May 09 '14 at 23:58
  • I think not, in the code I posted with my question the function defined as the constructor, the one which equalizes about 15 int variables with 0, aren't this all arguments? – Mohamed Ahmed May 10 '14 at 00:01
  • This what the code looks like now, http://pastebin.com/9wjP6Eis, I have added lfsr::lfsr() but the compiler says that this is an extra qualifier. – Mohamed Ahmed May 10 '14 at 00:06
  • @MohamedAhmed `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 <>)` ...???? What is your intention? Just `lfsr();` – ikh May 10 '14 at 07:37