Caesar password Encryption C language simple implementation

Source: Internet
Author: User

Caesar encryption (Julius Caesar) This method replaces each letter in a message with the letter that follows the fixed distance in the alphabet. (If it goes beyond the letter Z, it bypasses the starting position of the alphabet.) For example, if each letter is replaced with a letter from two positions in the alphabet, then Y is replaced with a,z and replaced by B. )

Then write the program .....

User input message and number of shifts to encrypt:

Do not change the letter ......

#include <stdio.h>#include<string.h>intMain () {Charpasswd[ -],encrypted[ -]; intI,j,k,t,move;  while(1) {printf ("Enter message to be encrypted:");        Gets (passwd); printf ("Enter Shift Amount (1-25):"); scanf ("%d%*c",&move);  for(i=0; I<strlen (passwd); i++)        {            if(Passwd[i] >='A'&& Passwd[i] <='Z') {Passwd[i]= ((passwd[i]-'A') +move)% -+'A'; }            Else if(Passwd[i] >='a'&& Passwd[i] <='Z') {Passwd[i]= ((passwd[i]-'a') +move)% -+'a'; }} printf ("%s", passwd); printf ("\ n"); }    return 0;}

And that's it.

such as input

Go head, make my day.

3

Output: Jr dkhdg, PDNH pb gdb.

......................................................

If this is the case, the input will decrypt:

Jr DKHDG, PDNH pb gdb.

23

Output: Go head, make my day.

Caesar password Encryption C language simple implementation

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.