Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   CEASAR CIPHER simple coding algorithm (http://www.go4expert.com/forums/ceasar-cipher-simple-coding-algorithm-t26022/)

jose_peeterson 10Jun2011 13:24

CEASAR CIPHER simple coding algorithm
 
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;   
 
}

*/


jose_peeterson 19Jun2011 18:44

Re: CEASAR CIPHER simple coding algorithm
 
ok i solved the propblem on my own
so you dont have to bother with this thanks
:)


All times are GMT +5.5. The time now is 00:02.