Anda di halaman 1dari 8

Cryptography

• In cryptography, a Caesar cipher, also known


as Caesar's cipher, the shift cipher, Caesar's
code or Caesar shift.
• It is a type of substitution cipher in which each
letter in the plain text is replaced by a letter some
fixed number of positions down the alphabet.
• For example, with a left shift of 3, D would be
replaced by A, E would become B, and so on.
• The method is named after Julius Caeser.
• #include<stdio.h>

• void main()
• {

• char c[20];
• int a1[20];
• int a2[20];
• int n=0;
• int k=0;
• printf("\nPlease Enter the key value: ");
• scanf("%d",&k);

• printf("\nHow many letters in the text? : ");


• scanf("%d",&n);

• int i;
• printf("\n Please enter a word to be encoded:");

• for(i=-1;i<n;++i)
• {
• scanf("%c",&c[i]);
• }

• int temp=0;
• int j=0;
• int count=0;
• for(i=0;i<=n;++i)
• {
• l1:temp=(int)c[i];

• if(c[i]==' ')
• {
• i=i+1;
• count=count+1;
• goto l1;
• }

• if(65<=temp && temp<=91)


• a1[j]=temp%65;
• else
• if(97<=temp<=123)
• a1[j]=temp%97;

• a2[j]=(a1[j]+k)%26;
• ++j;
• }
• n=n-count;
• printf("\nThe encoded cipher is: ");
• char c2[20];
• for(i=0;i<n;++i)
• {
• c2[i]=(char)(a2[i]+97);
• printf("%c",c2[i]);
• }
• printf("\n\nDecoding it receiver side ");

• int a3[20];
• for(i=0;i<n;++i)
• a3[i]=(int)(c2[i]-97);

• for(i=0;i<n;++i)
• {
• if(a3[i]>=k)
• a3[i]=a3[i]-k;
• else
• a3[i]=a3[i]-15+26;
• }

• printf("\nThe text is: ");


• for(i=0;i<n;++i)
• {
• printf("%c",(char)(a3[i]+97));
• }

• }
• /*OUTPUT

• Please Enter the key value: 15

• How many letters in the text? : 5

• Please enter a word to be encoded:hello

• The encoded cipher is: wtaad

• Decoding it receiver side


• The text is: hello

• Please Enter the key value: 15

• How many letters in the text? : 12

• Please enter a word to be encoded:good morning

• The encoded cipher is: vddsbdgcxcv

• Decoding it receiver side


• The text is: goodmorning
• */

Anda mungkin juga menyukai