Created
December 3, 2022 14:16
-
-
Save LokeshKumarES/9fd3a218281669c9f7a48005720031f3 to your computer and use it in GitHub Desktop.
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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: | |
1. You must include your ID, name and section number as sample input. | |
2. The program should also include your ID as a prefix to all input sentences. | |
3. Each word should be encrypted separately. | |
4. 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. | |
5. Also, aftershifting, do append “ay” at the end of the word. So, a word “trend” become “ndtreay”. | |
6. If a word starts with a vowel letter, then it should be encrypted by simply appending "way". For example, “end” becomes “endway”. | |
7. The letter 'y' is a treated as a consonant if it appears as the first letter of a word (yard ->rdyaay). | |
8. 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 | |
9. Also, "sch" at the beginning should become "sk" at the end. Eg: schooner -> oonerskay | |
10. 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.” | |
''' | |
str_name = input("Enter String: ") | |
u_id = 2 | |
# str_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}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment