CEASAR CIPHER simple coding algorithm

Discussion in 'C' started by jose_peeterson, Jun 10, 2011.

  1. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    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 a moderator: Jun 10, 2011
  2. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    ok i solved the propblem on my own
    so you dont have to bother with this thanks
    :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice