Monday, 22 April 2013

Monoalphabetic Algorithm in C

This blog is about implementation of Monoalphabetic cipher algorithm in c.

Hope that this will help to understand the concept Monoalphabetic cipher algorithm.

For any query regarding c/c++ concept please contact me at khimanichirag@gmail.com

     #include<stdio.h>  
     #include<conio.h>  
     #include<string.h>  
     void main()  
     {  
           char s[30],k[27],c[30];  
           int i, index;  
           clrscr();  
           printf("Enter plain text: ");  
           gets(s);  
           printf("\nEnter key with 26 character:");  
           for(i=0;i<26;i++)  
           {  
                printf("\n%c",i+97);  
                k[i]=getch();  
                printf("%c",k[i]);  
           }  
           for(i=0;i<strlen(s);i++)  
           {  
                index=s[i]-97;  
                c[i]=k[index];  
           }  
           printf("Your cipher text is:");  
           for(i=0;i<strlen(s);i++)  
           {  
               printf("%c",c[i]);  
           }  
            getch();  
      }  

3 comments:

  1. Can we use rand() function in this program??

    ReplyDelete
  2. Thank you for your help.But, this code is not working...Please verify it once!

    ReplyDelete