Sign InNuggetsCoursesCodePadCheatsheet

Caesar Cipher

A Caesar cipher is one of the earliest and simplest types of encryption. Its name comes from the fact that it was used by Julius Caesar to communicate in secret with his generals. It is a type of substitution cipher in which each letter in the original message is shifted across the alphabet with a hidden key number. For example, with a shift of 2, 'A' would be replaced by 'C', 'B' would become 'D', 'C' would become 'E', and so on. The message "Hello" becomes "Jgnnq" after the encryption, which is no longer readable at a simple glance.

# Write a program to encrypt a single character using Caesar cipher. alphabet = 'abcdefghijklmnopqrstuvwxyz' # Ask the user to enter a key between 1 and 25 and convert the input string into an integer. # Ask the user to enter a lowercase character. # Find the postion of the character in the alphabet. For example, character a's position is 0. # Find the position of the encrypted character by adding the entered key to its position. # If the new position is 26, go back to position 0. (Hint: use % operator) # Print out the encrypted character.
© CS Wonders·Home·About·Contact·Classes·Gallery·Glossary·Fun Facts