Skip to content

Instantly share code, notes, and snippets.

@RaMSFT
Created October 27, 2022 04:43
Show Gist options
  • Save RaMSFT/f5e62b138367e559d5c0afb0b2743558 to your computer and use it in GitHub Desktop.
Save RaMSFT/f5e62b138367e559d5c0afb0b2743558 to your computer and use it in GitHub Desktop.
def encrypt_shift_left(decode_str):
"""encode the given string (a step down to next alphabest)
a <- c
b <- d
...
k <- m
o <- q
e <- g
..
z <- b
"""
new_string = ''
for decode_char in decode_str.lower():
if decode_char.isalpha():
ascii_value = ord(decode_char)
new_ascii = (ascii_value + 26 - 2) if (ascii_value <= 98) else (ascii_value - 2)
#print(new_ascii)
new_char = chr(new_ascii)
else:
new_char = decode_char
new_string = new_string + new_char
return new_string
print(encrypt_shift_left("Hello Welcome to Python..!!"))
print(encrypt_shift_left("I am Ramesh..."))
print(encrypt_shift_left("You're reading in Medium"))
print(encrypt_shift_left("Please subscribe to my stories"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment