Any C++ coders on here?
ya
U know what an LFSR is??
linear feedback shift register
is a shift register whose input bit is a linear function of its previous state.
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?
take it easy! first let me understand wass u r problem is ....
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
now can u understand or understood him
i know what it is..the program isnt working
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);
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
whats that
wass your processor imean in bit counts 64 or 32
32
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);
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
i wrote my own..not this
try to write it
#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(); }
this is my code
thats an error coding
the seed function onwards is giving bugs
error where?
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
if this is c++ than i am not going to take computer science in 11th and 12th standard ..:) just joking ... gr8 work @Master.RohanChakraborty
BUT WHERE?
thanks
see the codes i posted
So?
try to resolve single mistake #error in brackets
can you tell me which line please?
clrscr(); int d;
thanks Princess
you forget about brackets {
thats all i found
The brackets are there..i told you theres no syntactical error
FFM?
then some coding errors
Join our real-time social learning platform and learn together with your friends!