importredefdecode(str):# check whether input string is valid
if(first_digit:=re.search(r"[a-zA-Z]",str))isNone:return"Impossible to decode"else:# extract the integer and text from string
decode_num=int(str[0:first_digit.start()])text=str[first_digit.start():]result_str=""# loop through all characters to decode string
forcharintext:index=ord(char)-ord('a')found=False# loop through all alphabets to decode string
fornuminrange(0,26):ifnum*decode_num%26==index:# if a character can be encoded in multiple alphabets, then it is impossible to decode
iffound:return"Impossible to decode"else:result_str+=chr(ord('a')+num)found=Trueifnotfound:return"Impossible to decode"returnresult_strprint(decode("6015ekx"))print(decode("5057aan"))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In python