#Challenge 1
alpha_chr = "abcdefghijklmnopqrstuvwxyz"
enocded_letters = "zabcdefghijklmnopqrstuvwxy"
def perform_ceaser (user_input):
result_str=""
for letter in user_input:
if letter == " ":
result_str += " "
else:
result_str += enocded_letters[alpha_chr.find(letter)]
return result_str
usr_input=""
domain="abcdefghijklmnopqrstuvwxyz "
while True:
usr_input = input("Enter a valid string to perform encoding").lower()
valid = 1
for x in usr_input:
if domain.find(x) == -1:
valid = 0
break
if valid == 1:
break
print ("The encoded string is ",perform_ceaser(usr_input))
#Challenge 2
alphanum_chr = "abcdefghijklmnopqrstuvwxyz0123456789"
enocded_letters = "zabcdefghijklmnopqrstuvwxy9012345678"
def perform_ceaser (user_input):
result_str=""
for letter in user_input:
if letter == " ":
result_str += " "
else:
result_str += enocded_letters[alphanum_chr.find(letter)]
return result_str
usr_input=""
domain="abcdefghijklmnopqrstuvwxyz0123456789 "
while True:
usr_input = input("Enter a valid string to perform encoding").lower()
valid = 1
for x in usr_input:
if domain.find(x) == -1:
valid = 0
break
if valid == 1:
break
print ("The encoded string is ",perform_ceaser(usr_input))
#Challenge 3
encode_1=".?“$([|=!:#^/{_"
encode_2=",;&%)]-~' @*\}+"
def perform_ceaser_punc (user_input):
result_str=""
for letter in user_input:
idx1 = encode_1.find(letter)
idx2 = encode_2.find(letter)
if idx1 > -1:
result_str += encode_2[idx1]
else:
result_str += encode_1[idx2]
return result_str
usr_input=""
domain=".?“$([|=!:#^/{_,;&%)]-~' @*\}+"
while True:
usr_input = input("Enter valid punctuation characters to perform encoding")
valid = 1
for x in usr_input:
if domain.find(x) == -1:
valid = 0
break
if valid == 1:
break
print ("The encoded string is ",perform_ceaser_punc(usr_input))
#Challenge 4
alpha_chr = "abcdefghijklmnopqrstuvwxyz"
enocded_letters = "zabcdefghijklmnopqrstuvwxy"
def perform_ceaser (user_input):
result_str=""
space_cnt=0
for letter in user_input:
if letter == " ":
result_str += ":"
space_cnt += 1
else:
result_str += enocded_letters[alpha_chr.find(letter)-space_cnt]
return result_str
usr_input=""
domain="abcdefghijklmnopqrstuvwxyz "
while True:
usr_input = input("Enter a string to perform encoding").lower()
valid = 1
for x in usr_input:
if domain.find(x) == -1:
valid = 0
break
if valid == 1:
break
print ("The encoded string is ",perform_ceaser(usr_input))
#Challenge 5
alpha_chr = "abcdefghijklmnopqrstuvwxyz"
enocded_letters = "zabcdefghijklmnopqrstuvwxy"
def ceaser_decode (user_input):
result_str=""
for letter in user_input:
if letter == " ":
result_str += " "
else:
result_str += alpha_chr[enocded_letters.find(letter)]
return result_str
usr_input=""
domain="abcdefghijklmnopqrstuvwxyz "
while True:
usr_input = input("Enter a valid string to perform decoding").lower()
valid = 1
for x in usr_input:
if domain.find(x) == -1:
valid = 0
break
if valid == 1:
break
print ("The decoded string is ",ceaser_decode(usr_input))
#Challenge 6
num_chr = "0123456789.?“$([|=!:#^/{_"
enocded_letters = "9012345678,;&%)]-~' @*\}+"
def ceaser_decode (user_input):
result_str=""
for letter in user_input:
if letter == " ":
result_str += " "
else:
result_str += num_chr[enocded_letters.find(letter)]
return result_str
usr_input=""
domain="0123456789.?“$([|=!:#^/{_,;&%)]-~' @*\}+ "
while True:
usr_input = input("Enter encoded number or punctuations to perform decoding")
valid = 1
for x in usr_input:
if domain.find(x) == -1:
valid = 0
break
if valid == 1:
break
print ("The decoded string is ",ceaser_decode(usr_input))