caeser_cipher
"/home/yossef/notes/courses/hashing/caeser_cipher.md"
path: courses/hashing/caeser_cipher.md
- **fileName**: caeser_cipher
- **Created on**: 2025-02-27 23:24:46
# chr convert the number to char for exmpale chr(65) => A
# ord is the reverse of chr convert char to number ord(A) => 65
# so now this work by shifting each ch in text by specific number
# like a => 26 after shifting 3 times 26 + 3 = 27 => d
def encrypted_data(plain_text, key):
"""
so this function it's implementation for ceaser cipher hashing
- plain_text(string) => param for text that want to change
- key(int) => param for the number of shifting want to do
@reutrn new hashing text cipher_text(string)
"""
cipher_text = "" # initlization the cipher_text
for i in range(len(plain_text)):
if i == " ": # if ch == space adding space to return hashing value
cipher_text += " "
else:
ch_value = ord(plain_text[i])+key # starting shifting
# this mean is the letter is captal
if ch_value > ord("z"):
cipher_text += chr(ch_value - 26) # if captal value
else:
cipher_text += chr(ch_value) # if small value
return cipher_text
print(encrypted_data("test", 2))
# output => vguv
# for decription the hashing it's only change in code
ch_value = ord(plain_text[i])-key
continue:./transposition_cipher.md
before:./playfair_ceaser.md