Computer Graphics Program source codes with full description.

Study of Various C Graphics Functions

Implementation and Using mouse in DOS

Implementation of DDA line algorithm with source code in C/C++.

Implementation of Bresenham Line algorithm with source code in C/C++.

Implementation of Midpoint Line algorithm with source code in C/C++.

Implementation of Bresenham Circle algorithm with source code in C/C++.

Implementation of Mid-point Circle algorithm with source code in C/C++.

Implementation of Mid-point Ellipse algorithm with source code in C/C++.

Implementation of Polygon Filling using Scan Fill with source code in C/C++.

Implementation of Polygon Filling using Flood Fill with source code in C/C++.

Implementation of Polygon Filling using Boundary Fill Algorithms.

Implementation of algorithm of 2D Transformation of an Object with source code in C/C++.

Implementation of Line Clipping using Cohen- Sutherland algorithm with source code in C/C++.

Implementation of Line Clipping using Liang-Barky algorithm with source code in C/C++.

Implementation of Polygon clipping using Sutherland-hodgeman algorithm with source code in C/C++.

Search

Friday 24 June 2011

Polyalphabetic cipher encryption-decryption

the source code for Polyalphabetic cipher encryption-decryption is as follows in c..



#include<stdio.h>
#include<conio.h>
#include<string.h>


char pt[40]={'\0'},key[40]={'\0'},ct[40]={'\0'},pta[40]={'\0'},k[40]={'\0'};
int i,j;      // global values

void main()
{
            clrscr();
            printf("\nEnter the keyword:\n");
            gets(k);//read the key
            printf("\nEnter the Plain text:\n");
            gets(pt);    //read the plain text

            // print the table
            printf("The convergen matrix\n");
            printf("\n   ");
            for(j=97;j<=122;j++)
            {
                        printf(" %c",j);
            }

            printf("\n--------------------------------------------------------\n");
            for(i=97;i<=122;i++)
            {
                        printf("%c |",i);
                        for(j=97;j<=122;j++)
                        {

                                    if(((i+j))>219)
                                    {

                                                printf(" %c",toupper((i+j)-123));
                                    }
                                    else
                                    {
                                                printf(" %c",toupper((i+j)-97));
                                    }
                        }
                        printf("\n");
            }
            // for keyword
            j=0;
            for(i=0;i<strlen(pt);i++)
            {
                        key[i]=k[j];
                        if(j==(strlen(k)-1))
                        {
                                    j=0;
                        }
                        else
                        {
                                    j++;
                        }
            }
            for(i=0;i<(strlen(pt)-1);i++);
            k[i]='\0';
            printf("\nThe encrypted text is:\n");
            // encryption
            for(i=0;i<strlen(pt);i++)
            {
                        if(97<=(int)pt[i] && (int)pt[i]<=122)
                        {

                                    if(((int)pt[i]+(int)key[i])>219)
                                    {
                                                ct[i]=(int)pt[i]+(int)key[i]-123;
                                    }
                                    else
                                    {
                                                ct[i]=(int)pt[i]+(int)key[i]-97;
                                    }
                                    printf("%c",toupper(ct[i]));
                        }
                        else
                        {
                                    ct[i]=pt[i];
                                    printf("%c",pt[i]);
                        }
            }
            // decryption
            printf("\n\nDecrypted text is:\n");
            for(i=0;i<strlen(ct);i++)
            {
                        if(97<=(int)ct[i] && (int)ct[i]<=122)
                        {

                                    if(((int)ct[i]-(int)key[i])<0)
                                    {
                                                pta[i]=((int)ct[i]-(int)key[i])+123;
                                    }
                                    else
                                    {
                                                pta[i]=(int)ct[i]-(int)key[i]+97;
                                    }
                                    printf("%c",pta[i]);
                        }
                        else
                        {
                                    pta[i]=ct[i];
                                    printf("%c",pta[i]);
                        }
            }
            getch();
}


output:




No comments:

Post a Comment

Copyright Text

Copyright @ LDRP Student Community, webmaster Rahul Bhadauriya