You are invited to participate in an encryption algorithm competition. Encryption is a method to change the formation of the message using pre-defined rules. After encryption, the message becomes secure and illegible. Develop a program that takes user input as a string sentence and prints its encryption version using the following rules:
You are invited to participate in an encryption algorithm competition.
Encryption is a method to change the formation of the message using pre-defined rules.
After encryption, the message becomes secure and illegible.
Develop a program that takes user input as a string sentence and prints its encryption version using the following rules:
- You must include your ID, name and section number as sample input.
- The program should also include your ID as a prefix to all input sentences.
- Each word should be encrypted separately.
- If a word starts with consonant letter, then that word should be shifted two places in circular way. For example, “trend” become “ndtre”, “brown” become “wnbro”, etc.
- Also, aftershifting, do append “ay” at the end of the word. So, a word “trend” become “ndtreay”.
- If a word starts with a vowel letter, then it should be encrypted by simply appending “way”. For example, “end” becomes “endway”.
- The letter ‘y’ is a treated as a consonant if it appears as the first letter of a word (yard ->rdyaay).
- As a vowel if it appears at an interior location (at mid or somewhere) take consonants before the first vowel shift to end. Eg: crybaby-> abycrybay
- Also, “sch” at the beginning should become “sk” at the end. Eg: schooner -> oonerskay
- Capitalized words should be capitalized after transformation. Eg: Sam -> Amsay A sample input is: “Brown fox jumps a yard.” after encryption “22k-1234 Wnbroay oxfay psjumay away rdyaay.”
1 Answers
str_name = input("Enter String: ") u_id = 2 # name = 'trend' sec_num = 10 in_str = str(u_id) + str_name + str(sec_num) res_str = '' user_id = '' act_str = '' res_str_list = [] sch_flag = False y_flag = False sch_flag = False for i in in_str: if i.isalpha(): act_str += i act_str = act_str.strip() alpha_num_str = in_str.split(act_str) if len(alpha_num_str)>1: sec_str = alpha_num_str[1] user_id = alpha_num_str[0] elif len(alpha_num_str)==1: user_id = alpha_num_str[0] sec_str = None else: user_id = None actual_list = list(act_str) act_list = list(act_str.lower()) if list('sch') == act_list[:3]: sch_flag = True vowel_list = ['a', 'i', 'o', 'e', 'u'] # if first aplhabet is vowel if act_list[0].lower() in vowel_list: res_str_list = act_list[:] res_str_list.extend(['w', 'a', 'y']) # if first alphabet is constant if act_list[0].lower() not in vowel_list: if sch_flag: act_list = act_list[3:] res_str_list = act_list[:] for i in range(len(act_list)): if i>0: if 'y' in act_list[i:]: y_flag = True else: y_flag = False if y_flag: if act_list[i].lower() in vowel_list: res_str_list = act_list[i:] res_str_list.extend(act_list[:i]) else: pass else: index_i = (i+2) - len(act_list) res_str_list.remove(act_list[i]) res_str_list.insert(index_i, act_list[i].lower()) if sch_flag: res_str_list.extend(['s','k']) res_str_list.extend(['a', 'y']) res_str = user_id + '-' + str(sec_num) + ' ' + ''.join(res_str_list) print(f"Input String: {in_str}") print(f"Output: {res_str}")
https://gist.github.com/LokeshKumarES/9fd3a218281669c9f7a48005720031f3