1. Password for the shift of the classical code

Source: Internet
Author: User

Implementation code:

#include <stdio.h>
void Main ()
{
void Jiami ();
void Jiemi ();
int C;
printf ("==============================/n");
printf ("Shift cipher Encryption System/n");
printf ("Input 1 Select Encryption | | Input 0 Select decrypt/n ");
printf ("==============================/n");
printf ("Please select:");
scanf ("%d", &c);
if (c==1)
Jiami ();
Else
Jiemi ();
}
void Jiami ()
{
int a[100],b[100],i,n,k;
printf ("Please enter the number of characters you want to encrypt:");
scanf ("%d", &n);
printf ("Please enter the encryption key:");
scanf ("%d", &k);
printf ("Please enter a Cryptographic object:");
for (i=0;i<n;i++)
scanf ("%d", &a[i]);
for (i=0;i<n;i++)
{
b[i]= (a[i]+2)%26+65;
printf ("%5c", B[i]]);
}
printf ("/n");
}
void Jiemi ()
{
int a[100],b[100],c[100],i,n,k;
printf ("Please enter the number of characters to decrypt:");
scanf ("%d", &n);
printf ("Please enter the decryption key:");
scanf ("%d", &k);
printf ("Please enter the decrypted object:");
for (i=0;i<n;i++)
scanf ("%d", &a[i]);
for (i=0;i<n;i++)
{
b[i]= (a[i]-k)%26;
if (b[i]<0)
c[i]=b[i]+26+65;
Else
c[i]=b[i]+65;
printf ("%5c", C[i]);
}
printf ("/n");
}

This code is written by itself, published here mainly want to get expert guidance, such as: Do not need to enter the number of encryption characters, code How to change more reasonable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.