32-Bit LFSR Encryption on a String in C++

0

I am trying to implement a LFSR to encrypt a string, but the catch is is that only on the 8th step of the LFSR is when the lowest byte is collected.

My current code encrypts correctly (I believe), but not in the format I would like.

I have to use the initial value provided, and the feedback value provided.

Any help would be appreciated.

My Code:

unsigned char *Crypt(unsigned char *data, int dataLength, unsigned int initialValue){
unsigned int a = 0x87654321; //Feedback Value

unsigned int b = initialValue;
int leastSigBit, count;

for (int i = 0; i < dataLength; i++)
{
    count = 0;
    data[i] = (data[i]) ^ ((b & 0x0000000F)); //Extracting the lowest byte
    do
    {
        count++;
        leastSigBit = b & 1; //Make leastSigBit the output bit
        b >>= 1;             //Shift Register
        if (leastSigBit)
            b ^= a; //If leastSigBit is 1, then XOR feedback product of the 32-bit shift register

    } while (count % 8 != 0); //On the 8th step it will stop loop and extract lowest byte
}

return data;}


int main(){

unsigned int initialVal = 0x12345678;
unsigned char *data;
int dataLength = 5;
int i;

data[0] = 'a';
data[1] = 'p';
data[2] = 'p';
data[3] = 'l';
data[4] = 'e';

cout << endl;
cout << "Original Message: "; //Print Original Data
cout << data << endl;

cout << "Encrypted Message: ";
Crypt(data, dataLength, initialVal);
for (int i = 0; i < dataLength; i++)
    cout << "\\x" << hex << (int)data[i]; //Print Encrypted Data
cout << endl;

cout << "Recovered Message: ";
Crypt(data, dataLength, initialVal);
cout << data << endl; //Printing Recovered Message

cout << endl;

return 0;}
c++
algorithm
lfsr

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0