Ejemplo n.º 1
0
unsigned char encrypt( unsigned char k1, unsigned char k2, unsigned char plaintext, unsigned char vector ) 
{
  unsigned char buffer1 ;
  unsigned char buffer2 ;
  
  //Add to vector 
  buffer1 = plaintext ^ vector ;

  //Initial permutation
  buffer2 = permutations( buffer1, 0 ) ;  

  //fk1
  buffer1 = f_function( buffer2, k1 ) ;

  //Switch
  buffer2 = switch_function( buffer1 ) ;
  
  //fk2
  buffer1 = f_function( buffer2, k2 ) ;
  
  //Final Permutation
  return permutations( buffer1, 1 ) ;   
}
Ejemplo n.º 2
0
unsigned char decrypt( unsigned char k1, unsigned char k2, unsigned char ciphertext, unsigned char vector )
{
  unsigned char buffer1 ;
  unsigned char buffer2 ;
  
  //Initial permutation
  buffer2 = permutations( ciphertext, 0 ) ;
  
  //fk2
  buffer1 = f_function( buffer2, k2 ) ;
  
  //Switch
  buffer2 = switch_function( buffer1 ) ;
  
  //fk1
  buffer1 = f_function( buffer2, k1 ) ;
  
  //Final Permutation
  buffer2 = permutations( buffer1, 1 ) ;
  
  //Add to vector 
  return buffer2 ^ vector ;
}
Ejemplo n.º 3
0
void Scwt_phase(float *input, double *Oreal, double *Oimage,
  double *f, int *pnboctave, int *pnbvoice, int *pinputsize,
  float *pcenterfrequency)
{
  int nboctave, nbvoice, i, j, inputsize;
  float centerfrequency, a;
  double *Ri2, *Ri1, *Ii1, *Ii2, *Rdi2, *Idi2, *Ii, *Ri;
  double *Odreal, *Odimage;


  centerfrequency = *pcenterfrequency;
  nboctave = *pnboctave;
  nbvoice = *pnbvoice;
  inputsize = *pinputsize;

  /* Memory allocations
     ------------------*/
  if(!(Odreal = (double *)calloc(inputsize*nbvoice*nboctave, sizeof(double))))
    error("Memory allocation failed for Ri1 in cwt_phase.c \n");
  if(!(Odimage = (double *)calloc(inputsize*nbvoice*nboctave, sizeof(double))))
    error("Memory allocation failed for Ii1 in cwt_phase.c \n");

  if(!(Ri1 = (double *)calloc(inputsize, sizeof(double))))
    error("Memory allocation failed for Ri1 in cwt_phase.c \n");
  if(!(Ii1 = (double *)calloc(inputsize, sizeof(double))))
    error("Memory allocation failed for Ii1 in cwt_phase.c \n");

  if(!(Ii2 = (double *)calloc(inputsize,sizeof(double))))
    error("Memory allocation failed for Ri2 in cwt_phase.c \n");
  if(!(Ri2 = (double *)calloc(inputsize,sizeof(double))))
    error("Memory allocation failed for Ri2 in cwt_phase.c \n");

  if(!(Idi2 = (double *)calloc(inputsize,sizeof(double))))
    error("Memory allocation failed for Ri2 in cwt_phase.c \n");
  if(!(Rdi2 = (double *)calloc(inputsize,sizeof(double))))
    error("Memory allocation failed for Ri2 in cwt_phase.c \n");

  if(!(Ri = (double *)calloc(inputsize, sizeof(double))))
    error("Memory allocation failed for Ri in cwt_phase.c \n");
  if(!(Ii = (double *)calloc(inputsize, sizeof(double))))
    error("Memory allocation failed for Ii in cwt_phase.c \n");

  for(i = 0; i < inputsize; i++){
    *Ri = (double)(*input);
    Ri++; input++;
  }
  Ri -= inputsize;
  input -= inputsize;
  
  /* Compute fft of the signal
     -------------------------*/
  double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);   
  
  /* Multiply signal and wavelets in the Fourier space
     -------------------------------------------------*/
  for(i = 1; i <= nboctave; i++) {
    for(j=0; j < nbvoice; j++) {
      a = (float)(pow((double)2,(double)(i+j/((double)nbvoice))));
      morlet_frequencyph(centerfrequency,a,Ri2,Idi2,inputsize); 
      multiply(Ri1,Ii1,Ri2,Ii2,Oreal,Oimage,inputsize);
      multiply(Ri1,Ii1,Rdi2,Idi2,Odreal,Odimage,inputsize);
      double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); 
      double_fft(Odreal,Odimage,Odreal,Odimage,inputsize,1); 
      Oreal += inputsize;
      Oimage += inputsize;  
      Odreal += inputsize;
      Odimage += inputsize; 
    }
  }

  Oreal -= inputsize*nbvoice*nboctave;
  Odreal -= inputsize*nbvoice*nboctave;
  Oimage -= inputsize*nbvoice*nboctave;
  Odimage -= inputsize*nbvoice*nboctave;

  free((char *)Ri2);
  free((char *)Ri1);
  free((char *)Ii1);
  free((char *)Ii2);
  free((char *)Ri);
  free((char *)Ii);

  /* Normalize the cwt and compute the f function
     --------------------------------------------*/
  normalization(Oreal, Oimage, Odreal, Odimage,
    inputsize*nbvoice*nboctave);

  f_function(Oreal, Oimage, Odreal, Odimage, f,
    centerfrequency,inputsize,nbvoice,nboctave);

  return;
}