Ask your own question, for FREE!
Mathematics 16 Online
OpenStudy (anonymous):

Any C++ coders on here?

OpenStudy (anonymous):

ya

OpenStudy (anonymous):

U know what an LFSR is??

OpenStudy (anonymous):

linear feedback shift register

OpenStudy (anonymous):

is a shift register whose input bit is a linear function of its previous state.

OpenStudy (anonymous):

I wrote a program using classes and dynamic memory allocation to generate a key using an LFSR. It has no syntactical errors, though its getting hung up...logical errors galore..can u check it?

OpenStudy (anonymous):

take it easy! first let me understand wass u r problem is ....

OpenStudy (anonymous):

http://en.wikipedia.org/wiki/Linear_feedback_shift_register this talks about LSFR and is written by me and Jake luther so go to it

OpenStudy (anonymous):

now can u understand or understood him

OpenStudy (anonymous):

i know what it is..the program isnt working

OpenStudy (anonymous):

have you entered this or..... #include <stdint.h> uint16_t lfsr = 0xACE1u; unsigned bit; unsigned period = 0; do { /* taps: 16 14 13 11; characteristic polynomial: x^16 + x^14 + x^13 + x^11 + 1 */ bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1; lfsr = (lfsr >> 1) | (bit << 15); ++period; } while(lfsr != 0xACE1u);

OpenStudy (anonymous):

i wrote a simple code of accepting a seed and taps from a user and doing repeated xor, and then pushing the results into a key using a linked list

razor99 (razor99):

whats that

OpenStudy (anonymous):

wass your processor imean in bit counts 64 or 32

OpenStudy (anonymous):

32

OpenStudy (anonymous):

correct then its #include <stdint.h> uint32_t lfsr = 1; unsigned period = 0; do { /* taps: 32 31 29 1; characteristic polynomial: x^32 + x^31 + x^29 + x + 1 */ lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xD0000001u); ++period; } while(lfsr != 1u);

OpenStudy (anonymous):

i mean #include <stdint.h> uint32_t lfsr = 1; unsigned period = 0; do { /* taps: 32 31 29 1; characteristic polynomial: x^32 + x^31 + x^29 + x + 1 */ lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xD0000001u); ++period; } while(lfsr != 1u); this was u r input

OpenStudy (anonymous):

i wrote my own..not this

OpenStudy (anonymous):

try to write it

OpenStudy (anonymous):

#include <stdio.h> #include <conio.h> #include <iostream.h> #include <math.h> #include <string.h> int xor(int ta,int tb) { return (ta+tb)%2; } struct node { int d; node* l; } ; class key { node head; public: key() { head.d=0; head.l=NULL; } void inc(int ta) { node* temp; temp=new node; temp->d=ta; temp->l=&head; head=*temp; } void show(); } ; void key::show() { node* temp; temp=&head; while (temp!=NULL) { cout<<temp->d; temp=temp->l; } } class reg { int* beg; int* feedcheck; int size; public: reg() { cout<<"Enter no of elements in register: "<<endl; cin>>size; beg=new int[size]; feedcheck=new int[size]; cout<<"Register formed. Press any key to seed..."; getch(); } void seed(); void feedback(); int act(); } ; void reg::seed() { clrscr(); int d; cout<<"Enter seed of "<<size<<" digits: "<<endl; for (int i=0;i<size;i++) { cin>>d; beg[i]=d; } cout<<"Seeded.Press any key to input feedback points..."; getch(); } void reg::feedback() { int ch; int nf; int f; clrscr(); for (int i=0;i<size;i++) { feedcheck[i]=0; } cout<<"Enter no of feedback points: "<<endl; cin>>nf; cout<<"Enter feedback points, index starting from zero: "<<endl; for (i=1;i<=nf;i++) { cin>>f; feedcheck[f]=1; } cout<<"Register established...Press any key to begin key generation "; clrscr(); } int reg::act() { int res; for (int i=0;i<size;i++) { if (feedcheck[i]==1) { res=xor(res,beg[i]); } } for (i=size-2;i>=0;i--) { beg[i+1]=beg[i]; } beg[0]=res; return res; } void main() { key k; reg r; r.seed(); r.feedback(); int num; cout<<"Input bit length of key: "<<endl; cin>>num; for (int i=1;i<=num;i++) { k.inc(r.act()); } clrscr(); cout<<"Generated key: "<<endl; k.show(); getch(); }

OpenStudy (anonymous):

this is my code

OpenStudy (anonymous):

thats an error coding

OpenStudy (anonymous):

the seed function onwards is giving bugs

OpenStudy (anonymous):

error where?

OpenStudy (anonymous):

clrscr(); int d; cout<<"Enter seed of "<<size<<" digits: "<<endl; for (int i=0;i<size;i++) { cin>>d; beg[i]=d; } cout<<"Seeded.Press any key to input feedback points..."; getch(); } void reg::feedback() { int ch; int nf; int f; clrscr(); for (int i=0;i<size;i++) { feedcheck[i]=0; } cout<<"Enter no of feedback points: "<<endl; cin>>nf; cout<<"Enter feedback points, index starting from zero: "<<endl; for (i=1;i<=nf;i++) { cin>>f; feedcheck[f]=1; } cout<<"Register established...Press any key to begin key generation "; clrscr(); } int reg::act() { int res; for (int i=0;i<size;i++) { if (feedcheck[i]==1) { res=xor(res,beg[i]); } } for (i=size-2;i>=0;i--) { beg[i+1]=beg[i]; } beg[0]=res; return res; } void main() { key k; reg r; r.seed(); r.feedback(); int num; cout<<"Input bit length of key: "<<endl; cin>>num; for (int i=1;i<=num;i++) { k.inc(r.act()); } clrscr(); cout<<"Generated key: "<<endl; k.show(); getch(); } this are error clearly visibe

mathslover (mathslover):

if this is c++ than i am not going to take computer science in 11th and 12th standard ..:) just joking ... gr8 work @Master.RohanChakraborty

OpenStudy (anonymous):

BUT WHERE?

OpenStudy (anonymous):

thanks

OpenStudy (anonymous):

see the codes i posted

OpenStudy (anonymous):

So?

OpenStudy (anonymous):

try to resolve single mistake #error in brackets

OpenStudy (anonymous):

can you tell me which line please?

OpenStudy (anonymous):

clrscr(); int d;

OpenStudy (anonymous):

thanks Princess

OpenStudy (anonymous):

you forget about brackets {

OpenStudy (anonymous):

thats all i found

OpenStudy (anonymous):

The brackets are there..i told you theres no syntactical error

OpenStudy (anonymous):

FFM?

OpenStudy (anonymous):

then some coding errors

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!