Encryption is all the rage nowadays but let us not forget what it was like back before the advent of internet. I have written a small, simple cipher that takes texts, gets their char value, and adds or subtracts a certian given number from them aka "shifting" the keys.
If the receiving end has the direction and then number of the shift, he or she can easily decrypt the code. It's not a real cipher, and nothing important at all. Just something I've written as practice:
""" This is a simple alphabetical shift encypter. Enter -1 or 1 for the direction, your desired shift and laslty, the
text to cipher.
Written by Sami Dena ([email protected])
"""
def cipher(direction, shift, text):
text_split = list(text)
text_split = [ord(i) for i in text_split]
text_shift = [str(i + (direction * shift)) for i in text_split]
return str.join(',', text_shift)
def decipher(direction, shift, text):
text_split = str.split(text, ',')
text_shift = [chr(int(i) - (direction * shift)) for i in text_split]
return str.join('', text_shift)
if __name__ == '__main__':
string = "The encryption step performed by a Caesar cipher is often" \
" incorporated as part of more complex schemes, such as the Vigenère cipher" \
", and still has modern application in the ROT13 system. As with all single-alphabet" \
" substitution ciphers, the Caesar cipher is easily broken and in modern practice offers " \
"essentially no communication security."
encrypted_string = cipher(-1, 4, string)
print(encrypted_string)
print(decipher(-1, 4, encrypted_string))
Thanks a lot for your reviews.