ASCII Based Encryption

 Coding Problem Keys 

 ASCII Based Encryption 

 Problem Statement 

The program must accept a string S as the input. The program must encrypt the string S based on the following encryption technique.
    - Replace each vowel is S by the unit digit of its ASCII value.
    - Replace each consonant is S by the tenth digit of its ASCII value.
    - Replace each non-alphabet is S by the sum of digits in its ASCII value.
Then the program must print the encrypted string as the output.

 Input Format 

The first line contains S.

 Output Format 

The first line contains the encrypted string.

 Boundary Condition(s) 

1 <= Length of S < 100

 Example Input/Output 1 

 Input 

India#2020

 Output 

310578512512

 Explanation 

I is a vowel. So the unit digit of its ASCII (73) is printed as the output.
n is a consonant. So the tenth digit of its ASCII (110) is printed as the output.
d is a consonant. So the tenth digit of its ASCII (100) is printed as the output.
i is a vowel. So the unit digit of its ASCII (105) is printed as the output.
a is a vowel. So the unit digit of its ASCII (97) is printed as the output.
# is a non-alphabet. So the sum of digits in its ASCII (35) is printed as the output.
2 is a non-alphabet. So the sum of digits in its ASCII (50) is printed as the output.
0 is a non-alphabet. So the sum of digits in its ASCII (48) is printed as the output.
2 is a non-alphabet. So the sum of digits in its ASCII (50) is printed as the output.
0 is a non-alphabet. So the sum of digits in its ASCII (48) is printed as the output.

 Example Input/Output 2 

 Input 

PKJCoders@123

 Output 

877610111101356

 Max Execution Time Limit: 500 millisecs 

 Solution 

 Programming Language: Python 3 Language 

def sumOfDigits(n):
    s=0
    while(n>0):
       s+=n%10
       n//=10
    return s
l=input().strip()
vowel="aeiouAEIOU"
for i in l:
    if(i.isalpha()):
        if i in vowel: print(ord(i)%10,end="")
        else: print(ord(i)//10%10,end="")
    elif(i.isnumeric()):
        print(sumOfDigits(int(i)+48),end="")
    else:
        print(sumOfDigits(ord(i)),end="")

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Maximum Sub Square Sum

Search String S2 in S1 Character Matrix

First N Repeated Characters

Largest of Tenth Digit and Unit Digit

String With Most Vowels

Reverse Column - First and Last