Detection des erreurs par les codes polynomiaux

Soyez le premier à donner votre avis sur cette source.

Vue 6 216 fois - Téléchargée 242 fois

Description

compiler par borland (dos)
c'est t'un tp sur la detection d'erreurs a l'aide de la division polynomial baser sur le Schéma électronique d'un diviseur polynomial

Procédé :
o (i) les registres ri sont mis à zéros
o (ii) les bits du mot à diviser sont insérés en entrée (k étapes), bits de poids fort en tête.
o (iii) les registres ri contiennent alors le reste, qu'on extrait (n-k étapes).
De nombreuses optimisations sont possibles :
o Lorsque gi=0 on supprime simplement la connexion et la porte ET !
o phase spécifique d'initialisation
je laisse une image du Schéma électronique ansi l 'exe (ex_)

Source / Exemple :


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<iostream.h>
#include<dos.h>
/////////////////////////////////////////////////////////
void sup(int j,int *t,int &n)
{
for(int i=j;i<n;i++) t[i]=t[i+1];
n--;
}
/////////////////////////////////////////////////////////
void ajout(int j,int *t,int &n,int k)
{
   for(int i=n-1;i>=j;i--) t[i+1]=t[i];
   t[j]=k;
   n++;
}
/////////////////////////////////////////////////////////
void mossica()
{ for (int i=0;i<2000;i+=400){sound(i);delay(50);nosound();}}
//////////////////////////////////////////////////////////
void msg_error(char *msg)
{
  gotoxy(10,2);mossica();
  highvideo();cprintf("%s                    ",msg);

}
/////////////////////////////////////////////////////////
void clean()
{
  gotoxy(10,2);
  highvideo();
  cprintf("                                                             ");

}
////////////////////////////////////////////////////////////
class poly_gene
{
private:  int *g,ng;
public:
      poly_gene(){g=new int [28];ng=0;}
      void principal_g();
      int *getg();
      int getng();
};
int *poly_gene::getg(){return g;}
int poly_gene::getng(){return ng;}
void poly_gene::principal_g()
{
  char s;
  int r=1;int pos=0;//ng max28
  gotoxy(2+ng,19);
  while(r)
  {
    s=getch();int t=(int)s;

      if(s=='1'){{if(ng<27){gotoxy(2+pos,19);putchar(s);ajout(pos++,g,ng,1);
		 gotoxy(2,19);puts("                             ");
		 gotoxy(2,19);for(int i=0;i<ng;i++)cout<<g[i];
		 clean();msg_error("ok->");gotoxy(2+pos,19);}
		  }}
      if(s=='0'){{if(ng<27){gotoxy(2+pos,19);putchar(s);ajout(pos++,g,ng,0);
		gotoxy(2,19);puts("                           ");
		 gotoxy(2,19);for(int i=0;i<ng;i++)cout<<g[i];
		 clean();msg_error("ok->");
		gotoxy(2+pos,19);
	       } }}
      if(s==8){{  if(pos>0){sup(pos-1,g,ng);
		gotoxy(2,19);puts("                           ");
		gotoxy(2,19);for(int i=0;i<ng;i++)cout<<g[i];
		gotoxy(2+--pos,19);}}}
     if(t==0){ t=getch();
               if(t==75){if(pos>0)gotoxy(1+pos--,19);}//deplacement gauche
		if(t==77){if(pos<27&&pos<ng)gotoxy(3+pos++,19);}
              }
     if(s==13){{
	   if(g[0]&&g[ng-1]&&ng>1)
	    {clean();msg_error("validation ok->");r=0;gotoxy(2+pos,19);}
	   else{clean();msg_error("le polynome doit commencer et finir avec 1");
	   gotoxy(2+pos,19);}
	   }}
      

  }
}
//////////////////////////////////////////////////////////////////////////
class trame
{
private:   int *t,nt;
public:   trame(){t=new int [56];nt=0;}
	  void t_princip();
	  int *gett();
	  int getnt();
};
int *trame::gett(){return t;}
int trame::getnt(){return nt;}
void trame::t_princip()
{
  char s;
  int r=1;int pos=0;//nt max81
  gotoxy(2+nt,23);
  while(r)
  {
    s=getch();int l=(int)s;
      if(s=='1'){if(nt<27){
		 gotoxy(2+pos,23);putchar(s);ajout(pos++,t,nt,1);
		 gotoxy(2,23);puts("                           ");
		 gotoxy(2,23);for(int i=0;i<nt;i++)cout<<t[i];
		 clean();msg_error("ok->");
		 gotoxy(2+pos,23);}
	       }
      if(s=='0'){if(nt<27){gotoxy(2+pos,23);putchar(s);ajout(pos++,t,nt,0);
		gotoxy(2,23);puts("                           ");
		 gotoxy(2,23);for(int i=0;i<nt;i++)cout<<t[i];
		 clean();msg_error("ok->");
		gotoxy(2+pos,23);

	       }  }
      if(s==8){  if(pos>0){sup(pos-1,t,nt);
		gotoxy(2,23);puts("                           ");
		gotoxy(2,23);for(int i=0;i<nt;i++)cout<<t[i];
		gotoxy(2+--pos,23);} }
     if(l==0){l=getch();
	      if(l==75){if(pos>0)gotoxy(1+pos--,23);}//deplacement gauche
	      if(l==77){if(pos<27&&pos<nt)gotoxy(3+pos++,23);}//deplacement droit
      }
      if(s==13){if(nt>1){clean();msg_error("ok->");r=0;gotoxy(2+pos,23);}
	       else{clean();msg_error("au mois deg 2");r=1;gotoxy(2+pos,23);}}

    }

}
////////////////////////////////////////////////////////////////////
void f_dep()
{
  textcolor(GREEN);
  gotoxy(1,2);mossica();cprintf("Messages:");
   gotoxy(1,14);highvideo();cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n\r");
   gotoxy(1,15);cprintf("º  station du depart   º\n\r");
   gotoxy(1,16);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍ»\n\r");
   gotoxy(1,17);cprintf("º     polynome genarateur     º\n\r");
   gotoxy(1,18);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
   gotoxy(1,19);cprintf("º                             º\n\r");
   gotoxy(1,20);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
   gotoxy(1,21);cprintf("º         trame emise         º\n\r");
   gotoxy(1,22);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
   gotoxy(1,23);cprintf("º                             º\n\r");
   gotoxy(1,24);cprintf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n\r");
}
////////////////////////////////////////////////////////////////////////
void f_arr()
{
 gotoxy(50,14); highvideo();
                 cprintf("       ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n\r");
 gotoxy(50,15);  cprintf("       º  station d'arriv?e   º\n\r");
 gotoxy(50,16);  cprintf("ÉÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
 gotoxy(50,17);  cprintf("º    polynome genarateur      º\n\r");
 gotoxy(50,18);  cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
 gotoxy(50,19);  cprintf("º                             º\n\r");
 gotoxy(50,20);  cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
 gotoxy(50,21);  cprintf("º         trame recue         º\n\r");
 gotoxy(50,22);  cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n\r");
 gotoxy(50,23);  cprintf("º                             º\n\r");
 gotoxy(50,24);  cprintf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
}
////////////////////////////////////////////////////////////////////////
void dep_sd()
{
for(int i=0;i<7;i++)
  {gotoxy(1,14+i);highvideo();cprintf("                               \n\r");
   gotoxy(1,14+i);cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n\r");
   gotoxy(1,15+i);cprintf("º  station du depart   º\n\r");
   gotoxy(1,16+i);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍ»\n\r");
   delay(100);}
   for(i=0;i<7;i++){gotoxy(1,13+i);puts("                          ");delay(100);}
   gotoxy(25,21);puts("       ");
   gotoxy(1,2);
   cprintf("                                                         ");
}
/////////////////////////////////////////////////////////////////////////
int xor(int a,int b)
{
  return a!=b;
}
/////////////////////////////////////////////////////////////////////////
void send_1()
{
  int x=3,y=24;
  for(int i=0;i<10;i++)
  {
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("º");cprintf("sending msg");cprintf("º");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   delay(100);
   gotoxy(x,y-3);
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("º           º");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   x++;y--;
  }
  for(i=0;i<10;i++)
  {
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("ºsending msgº");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   delay(100);
   gotoxy(x,y-3);
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("º           º");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   x+=2 ;y--;
  }
  gotoxy(32,3);cprintf("  >le msg<");
}
/////////////////////////////////////////////////////////
void eff_1()
{
  int x=3,y=24;
  gotoxy(1,22);cprintf("             ");
  gotoxy(1,23);cprintf("             ");
  gotoxy(1,24);cprintf("             ");
  for(int i=0;i<10;i++)
  {
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("             ");
   gotoxy(x,y-2);cprintf("             ");
   gotoxy(x,y-1);cprintf("             ");
   delay(100);
   x++;y--;
  }
  for(i=0;i<7;i++)
  {
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("             ");
   gotoxy(x,y-2);cprintf("             ");
   gotoxy(x,y-1);cprintf("             ");
   delay(100);
   x+=2 ;y--;
  }
   gotoxy(18,3);cprintf("             ");
   gotoxy(18,4);cprintf("             ");
   gotoxy(18,5);cprintf("             ");
   gotoxy(27,5);cprintf("                 ");
   gotoxy(27,6);cprintf("                 ");
   
}
///////////////
void send_2()
{
  int x=33,y=4;
  for(int i=1;i<10;i++)
  {
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("ºsending msgº");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   delay(100);
   gotoxy(x,y-3);
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("º           º");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   x+=2 ;y++;
  }
   for(i=0;i<13;i++)
  {

   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("ºsending msgº");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   delay(100);
   gotoxy(x,y-3);
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("º           º");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");
   y++;x++;
  }
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍ»");
   gotoxy(x,y-2);
   cprintf("º  msg recu º");
   gotoxy(x,y-1);
   cprintf("ÈÍÍÍÍÍÍÍÍÍÍͼ");

  }
  /////////////////////////
void eff_2()
{  int x=33,y=4;
  for(int i=1;i<10;i++)
  {
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
   cprintf("             ");
   gotoxy(x,y-2);
    cprintf("             ");
   gotoxy(x,y-1);
   cprintf("             ");
   delay(100);
   x+=2 ;y++;
  }
   for(i=0;i<13;i++)
  {

   gotoxy(x,y-3);textcolor(GREEN);highvideo();
    cprintf("             ");
   gotoxy(x,y-2);
    cprintf("             ");
   gotoxy(x,y-1);
    cprintf("             ");
   delay(100);
   y++;x++;
  }
   gotoxy(x,y-3);textcolor(GREEN);highvideo();
    cprintf("             ");
   gotoxy(x,y-2);
    cprintf("             ");
   gotoxy(x,y-1);
    cprintf("             ");}

/////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
void main()
{
 ohi: clrscr();
  f_dep();
  //////////////////////////////////////////////////////////
  poly_gene PG;
  PG.principal_g();
  /////////////////////////////////////////////////////////
  trame T;
  T.t_princip();
 ///////////////////////////////////////////////////////////
  int *t_;t_=new int [28];t_=T.gett();
   int *g_;g_=new int [28];g_=PG.getg();
   int nt_=T.getnt();
   int ng_=PG.getng();

  int matrix[48][28];
  for(int i=0;i<nt_+ng_;i++)
    for(int j=0;j<ng_;j++)
      matrix[i][j]=0;

for(i=0;i<nt_;i++) matrix[i+1][ng_-1]=t_[i];
for( i=0;i<ng_-1;i++) matrix[1][i]=matrix[1][i+1];
for(int k=1;k<nt_+ng_-1;k++)
{
	for(int j=ng_-1;j>=0;j--)
	{
	    if(!matrix[k][0])
		{     for(int i=0;i<ng_-2;i++) matrix[k+1][i]=matrix[k][i+1];
		       matrix[k+1][ng_-2]=matrix[k+1][ng_-1];
		}

		else
	{
			if(j==ng_-1){ matrix[k+1][ng_-2]=xor(matrix[k+1][ng_-1],1);}
		    else
			{
				if(g_[j])
					matrix[k+1][j-1]=xor(matrix[k][j],1);

		    else
					matrix[k+1][j-1]=matrix[k][j];
			}
		}
	}
}
dep_sd();
if(ng_+nt_<20)
{
     gotoxy(18,1);textcolor(GREEN);
    highvideo();
    cprintf("<simulation du traittement matriciel>\n");
    char al[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','#'};
    gotoxy(30,2);
    for(i=0;i<ng_-1;i++) cprintf("º%c",al[i]);cprintf("º");

    for(i=0;i<nt_+ng_;i++)
    {gotoxy(30,3+i);
    for(int j=0;j<ng_;j++)  {cprintf("º%d",matrix[i][j]);}
    cprintf("º");
    }
for(int j=nt_+ng_+ng_;j<24;j++)
   { gotoxy(30,j);
     for(i=0;i<ng_-1;i++) cprintf(" %d",matrix[nt_+ng_-1][i]);
    delay(100);
   }
   cprintf("\n");
   for(j=(nt_+ng_+ng_);j<23;j++)
   {
     for(i=0;i<ng_-1;i++) {gotoxy(30,j);cprintf("                                "); }
    delay(100);
   }

for(i=30;i>1+nt_;i--)
{gotoxy(i,23);
 for(int j=0;j<ng_-1;j++)cprintf("%d",matrix[nt_+ng_-1][j]);
 delay(100);gotoxy(i+ng_-1,23);cprintf("                                      ");
 }
clrscr();
for(i=0;i<PG.getng()-1;i++) t_[i+nt_]=matrix[ng_+nt_-1][i];
gotoxy(1,20);cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n\r");
gotoxy(1,21);cprintf("º  station du depart   º\n\r");
gotoxy(1,22);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍ»\n\r");
gotoxy(1,23);cprintf("º                             º\n\r");
gotoxy(1,24);cprintf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
gotoxy(2,23);for(i=0;i<nt_+ng_-1;i++) cprintf("%d",t_[i]);
for(i=0;i<3;i++)
{gotoxy(1,i+20);cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n\r");
 delay(100);gotoxy(1,i+19);cprintf("                           ");
}
for(int k=0;k<20;k++)
{ gotoxy(30-k,20);cprintf(" ");
  gotoxy(30-k,21);cprintf(" \n\r");
  gotoxy(30-k,22);cprintf("»\n\r");
  gotoxy(30-k,23);cprintf("º\n\r");
  gotoxy(30-k,24);cprintf("¼\n\r");
  delay(100);
  gotoxy(31-k,20);cprintf(" ");
  gotoxy(31-k,21);cprintf(" ");
  gotoxy(31-k,22);cprintf(" ");
  gotoxy(31-k,23);cprintf(" ");
  gotoxy(31-k,24);cprintf(" ");
}
send_1();eff_1();
gotoxy(21,10);cprintf("voullez vous intercepter le message Y/N");
char s;
s=getch();
if(s=='Y'||s=='y'){
clrscr();gotoxy(28,2);cprintf("interception du message");
gotoxy(28,20);cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n\r");
gotoxy(28,21);cprintf("º  Interception du msg º\n\r");
gotoxy(28,22);cprintf("ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍ»\n\r");
gotoxy(28,23);cprintf("º                             º\n\r");
gotoxy(28,24);cprintf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
int r=1;int pos=0;gotoxy(29+pos,23);
for(int i=0;i<nt_+ng_-1;i++) cprintf("%d",t_[i]);gotoxy(29+pos,23);
while(r)
{
    s=getch();int t=(int)s;
    if(s=='1'){gotoxy(29+pos,23);putchar(s);t_[pos]=1;
		 gotoxy(29,23);puts("                           ");
		 gotoxy(29,23);for(int i=0;i<nt_+ng_-1;i++)cout<<t_[i];
		 clean();msg_error("ok->");
		 gotoxy(29+pos,23);
	       }
    if(s=='0'){gotoxy(29+pos,23);putchar(s);t_[pos]=0;
		gotoxy(29,23);puts("                           ");
		 gotoxy(29,23);for(int i=0;i<nt_+ng_-1;i++)cout<<t_[i];
		 clean();msg_error("ok->");
		gotoxy(29+pos,23);
	       }
     if(t==0){t=getch();
		if(t==75)
		  {if(pos>1)gotoxy(27+pos--,23);}//deplacement gauche
		if(t==77){if(pos<nt_+ng_-2)gotoxy(30+pos++,23);}
	      }//deplacement droit
     if(s==13){clean();msg_error("ok->");r=0;gotoxy(29+pos,23);}

      
}
}

clrscr();send_2();eff_2();f_arr();
gotoxy(51,19);for(i=0;i<ng_;i++) cprintf("%d",g_[i]);
gotoxy(51,23);for(i=0;i<nt_+ng_-1;i++) cprintf("%d",t_[i]);
for(int i=0;i<nt_+ng_;i++)
    for(int j=0;j<ng_;j++)
      matrix[i][j]=0;

for(i=0;i<nt_+ng_-1;i++) matrix[i+1][ng_-1]=t_[i];
for( i=0;i<ng_-1;i++) matrix[1][i]=matrix[1][i+1];
for(k=1;k<nt_+ng_-1;k++)
{
	for(int j=ng_-1;j>=0;j--)
	{
	    if(!matrix[k][0])
		{     for(int i=0;i<ng_-2;i++) matrix[k+1][i]=matrix[k][i+1];
		       matrix[k+1][ng_-2]=matrix[k+1][ng_-1];
		}

		else
	{
			if(j==ng_-1){ matrix[k+1][ng_-2]=xor(matrix[k+1][ng_-1],1);}
		    else
			{
				if(g_[j])
					matrix[k+1][j-1]=xor(matrix[k][j],1);

		    else
					matrix[k+1][j-1]=matrix[k][j];
			}
		}
	}
}
for(i=0;(i<ng_-1)&&(!matrix[nt_+ng_-1][i]);i++);

if(i!=ng_-1) { gotoxy(18,12);cprintf("message mal transmit");}
else{  gotoxy(18,12);cprintf("message bien recu");}
}
else{clean();msg_error("memoire insufisante simulation impossible");}
gotoxy(18,14);cprintf("voullez vous continuer Y/N");
char s;
s=getch();
if(s=='Y'||s=='y') goto ohi;

   
}

Codes Sources

A voir également

Ajouter un commentaire Commentaire
Messages postés
16
Date d'inscription
mardi 14 juin 2005
Statut
Membre
Dernière intervention
4 novembre 2008

j'attend les commentaires !!

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.