Caesar Cipher

Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is shifted by a certain number of positions down the alphabet.

The encryption algorithm works by taking the plaintext and shifting each letter by a specified number of positions, called the key. For example, if the key is 3, then the letter A would be replaced by D, B would become E, C would become F, and so on.

The decryption algorithm works by reversing the process. The encrypted text is shifted back to its original position to reveal the plaintext.

Caesar Cipher is not a very secure encryption technique as it can be easily cracked by a brute force attack. However, it is useful for simple applications where security is not a major concern.

Example

Here is an example of Caesar Cipher:

Plaintext: ATTACK AT DAWN
Key: 3
Ciphertext: DWWDFN DW GDZQ

Code Example

Here is an example of a Python code that can encrypt a message using Caesar Cipher:

	def caesar_cipher(text, key):
	    result = ""
	    
	    for i in range(len(text)):
	        char = text[i]
	        
	        if char.isupper():
	            result += chr((ord(char) + key - 65) % 26 + 65)
	        elif char.islower():
	            result += chr((ord(char) + key - 97) % 26 + 97)
	        else:
	            result += char
	            
	    return result
	

Here is an example of how to use the function:

	text = "ATTACK AT DAWN"
	key = 3

	ciphertext = caesar_cipher(text, key)

	print("Ciphertext:", ciphertext)
	

Conclusion

Caesar Cipher is a simple encryption technique that can be useful for simple applications where security is not a major concern. However, it is not very secure and can be easily cracked by a brute force attack.