Tuesday, February 17, 2015

Turbo C++ for Windows 8 64 bit

Hello Everyone, in my previous posts I have shared links to download turbo c++ for windows xp and windows 7. From last few days I am getting requests from my blog readers to share a link to download turbo c++ for windows 8. So in this article I have shared about it and it will run in full screen. Just click on Download Now button to download turbo c++ for windows 8. I will not recommend you to use turbo C++ compiler because it is very old compiler. You should use some modern compiler like GCC.



Turbo C++ for Windows 8 64 bit
download 
http://www.softpedia.com/get/Programming/Coding-languages-Compilers/TurboCplusplus-for-Windows-7.shtml#download

Monoalphabetic cipher encryption-decryption.



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

void main()
{
            int i,j,pt,a3,a4,a;
            char a1[50],s1[10],a2[50],s2[50];
            clrscr();

            printf("Enter 0 for capital or 1 for Small latters\n");
            printf("Enter ; at the end of the plaintext\n");

            scanf("%d",&a);


            switch(a)
            {
             case 0:
             {
                        for(i=0;i<26;i++)
                        {
                                    a1[i]=i+65;
                                    printf("%c",a1[i]);

                        }

            printf("\nEnter values for each charater\n");

                        for(i=0;i<26;i++)
                        {

                                    cscanf("%c",&a2[i]);

                        }

             printf("\nEnter the plain text\n");


                        for(i=0;i<100;i++)
                        {
                                    cscanf("%c",&s1[i]);
                                    if(s1[i]==';')
                                         {     s1[i]='\0';
                                                break; }

                        }

            a3=strlen(s1);
            printf("\nThe cyfer text is:");
            for(i=0;i<a3;i++)

                        {for(j=0;j<26;j++)

                                    {       if(s1[i]==' ')
                                                  { printf(" ");}

                                           else if(s1[i]==a1[j])
                                                {

                                                    printf("%c",a2[j]);

                                                }

                                    }
                        }
                        break;   }
              case 1:
              {
                        for(i=0;i<26;i++)
                        {
                                    a1[i]=i+97;
                                    printf("%c",a1[i]);

                        }

                        printf("\nEnter values for each charater\n");

                        for(i=0;i<26;i++)
                        {
                                    cscanf("%c",&a2[i]);

                        }

                         printf("\nEnter the plain text\n");
                         for(i=0;i<26;i++)
                        {
                                    cscanf("%c",&s2[i]);
                                    if(s2[i]==';')
                                         {     s2[i]='\0';
                                                break; }


                        }

                        a4=strlen(s2);
                        printf("\nThe cyfer text is:");

                        for(i=0;i<a4;i++)

                                    {          for(j=0;j<26;j++)

                                           if(s2[i]==' ')
                                                { printf(" ");}
                                           else           {
                                                            if(s2[i]==a1[j])
                                                            {
                                                            printf("%c",a2[j]);
                                                            }

                                                }
                                    }
                }
               }
getch();

}

Caesar cipher encryption-decryption

#include<stdio.h>
#include<conio.h>
void main()
{
char pt[100],ct[100],dt[100];
int i,key;
clrscr();
printf("ENter the plain text and press ']' to terminate\n");
for(i=0; i<100; i++)
{
            scanf("%c",&pt[i]);
            if(pt[i]==']')
            {
                        pt[i]='\0';
                        break;
            }
}
printf("ENter the key\n");
scanf("%d",&key);
for(i=0; pt[i]!='\0'; i++)
{
            if(pt[i]>64 && pt[i]<91)
                        ct[i]=(pt[i]-65+key)%26+65;

            if(pt[i]>96 && pt[i]<123)
                        ct[i]=(pt[i]-97+key)%26+97;

            if(pt[i]==32)
                        ct[i]=pt[i];
}
printf("Plain text :\n");
for(i=0; pt[i]!='\0'; i++)
printf("%c",pt[i]);
printf("\nCeasar cipher:\n");
for(i=0; ct[i]!='\0'; i++)
printf("%c",ct[i]);
printf("\n");
for(key=0; key<26; key++)
{
            printf("For key %d ",key);
            for(i=0; ct[i]!='\0'; i++)
            {
                        if(ct[i]>64 && ct[i]<91)
                        {
                                    dt[i]=(ct[i]-39-key)%26+65;
                                    printf("%c",dt[i]);
                        }
                        if(ct[i]>96 && ct[i]<123)
                        {
                                    dt[i]=(ct[i]-71-key)%26+97;
                                    printf("%c",dt[i]);
                        }
                        if(ct[i]==32)
                        {
                                    dt[i]=ct[i];
                                    printf("%c",dt[i]);
                        }
            }
                        printf("\n");
}
getch();
}

Polyalphabetic cipher encryption-decryption

#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();
}


C Source Code Example for Ceaser Cipher

#include <stdio.h>
#include <ctype.h>

#define MAXSIZE 1024

void encrypt(char*);
void decrypt(char*);

int menu();

int
main(void)
{

char c,
     choice[2],
     s[MAXSIZE];

 while(1)
 {
 menu();

 gets(choice);

 if((choice[0]=='e')||(choice[0]=='E'))
 {
  puts("Input text to encrypt->");
  gets(s);
  encrypt(s);
 }
 else if((choice[0]=='d')||(choice[0]=='D'))
 {
  puts("Input text to decrypt->");
  gets(s);
  decrypt(s);
 }
 else
    break;
 }

 return 0;
}

void encrypt(char*str)
{
 int n=0;
 char *p=str,
   q[MAXSIZE];

 while(*p)
 {
  if(islower(*p))
  {
   if((*p>='a')&&(*p<'x'))
    q[n]=toupper(*p + (char)3);
   else if(*p=='x')
    q[n]='A';
   else if(*p=='y')
    q[n]='B';
   else
    q[n]='C';
  }
  else
  {
   q[n]=*p;
  }
  n++; p++;
 }
 q[n++]='\0';
 puts(q);
}

void decrypt(char*str)
{
 int   n=0;
 char *p=str,
   q[MAXSIZE];

 while(*p)
 {
  if(isupper(*p))
  {
   if((*p>='D')&&(*p<='Z'))
    q[n]=tolower(*p - (char)3);
   else if(*p=='A')
    q[n]='x';
   else if(*p=='B')
    q[n]='y';
   else
    q[n]='z';
  }
  else
  {
   q[n]=*p;
  }
  n++; p++;
 }
 q[n++]='\0';
 puts(q);
}

int menu()
{
 puts("To encrypt, input e or E\n");
 puts("To decrypt, input d or D\n");
 puts("To exit, input any other letter\n");
 puts("Your choice:->\n");
 return 0;
}