CEASAR CIPHER simple coding algorithm

jose_peeterson's Avatar, Join Date: May 2011
Contributor
a sentence is read using fgets(); and stored in an array, then the words need to be seperated and the shifted 3 places right in the ASCII code and then put back into the array then capiatlise the words. all other symbols left unchanged.
i got problems in seperating the words. only the first word is coded in my program.
please check my code
thanks...
note : my capitalise function is not done yet

Code:
#include<stdio.h>   // FIX THE BBBBBBBBBBBBUUUUUUUUUUUUUUGGGGGGGGGGGGGGG
#include<string.h> //  FIX THE bug..............

void read( char secret[]);
void convert(char secret[],int ascii[],int l);
void capitalise(char secret[],int ascii[],int l);

int main()

{
    
char secret[35];
int l,i,k=0;
int ascii[35];

 read(secret);   
  
                                           // printf("%s\n",secret);   
 l = strlen(secret);   
                                           // printf("%d",l);    
 l = l - 1;   
   
 convert(secret,ascii,l);

                                 //   printf(" %c \n",secret[4]);

 for(i = 0;i < l;i++);
  {
   if( (ascii[i] == 32) || (i == (l - 1)) )
    {
                                           //  printf("%d\n",i);
      
      while( (k <= i) && ascii[k] >= 97 && ascii[k] <= 122)
      {
       ascii[k] = ascii[k] + 3;
       
       secret[k] = ascii[k];
      
       k = k + 1; 
      
      }
    k = i + 1;
    
    }
        
  }
                                   //  printf("%d",i);
                                     printf("%s\n",secret);
// capitalise(secret,ascii,l);
 
return 0;    
    
}

void read(char secret[] )

{
 printf("Enter the secret to be CIPHERED.... : \n");

 fgets(secret,35,stdin);       
    
return;    
    
}

void convert(char secret[],int ascii[],int l)

{
 int i;

 for(i=0;i < l;i++)
  {
   ascii[i] =  secret[i]; 
  }   
                                   //    printf("%d",ascii[4]); 

return;    
    
}

/*void capitalise(char secret[],int ascii[],int l)

{

int i; 
     
 for(i =0;i <l;i++ )   
 {
  if(secret)    
     
     
     
     
 }


return;    
   
}

*/

Last edited by shabbir; 10Jun2011 at 13:36.. Reason: Code blocks
0
jose_peeterson's Avatar, Join Date: May 2011
Contributor
ok i solved the propblem on my own
so you dont have to bother with this thanks