Here is a simple implementation of an encryption tool in Python using the Caesar cipher method:
Explanation:
- The Caesar cipher is a simple substitution cipher that replaces each letter of the plaintext with a letter a certain number of positions down the alphabet (the shift).
- The
encrypt
function takes a plaintext message and a shift value as input and returns the corresponding ciphertext. It uses theord
function to get the ASCII code of the characters and thechr
function to convert the ASCII code back to characters. - The
decrypt
function takes a ciphertext message and a shift value as input and returns the corresponding plaintext. It is the reverse process of the encryption function. - The code sets the message and shift values and then calls the encryption and decryption functions to show how the same message can be encrypted and then decrypted.
No comments:
Post a Comment