Replace every character of string by character whose ASCII value is K times more than it

+1 vote

Secret Message

Description

You write all your passwords in a diary so that you don't forget them. But clearly this is too risky, so you came up with a simple plan, you will simply write it by shifting all the alphabets by a certain step. For eg: if you decide your step to be 3, then 'a' will become 'd', and 'k' will become 'n' and so for all alphabets. The last alphabets will simply circle back to 'a'. In this case, 'y' will become 'b' and so on. Now you just have to remember the step size, can then you can check the password anytime you want. You decided to write code to do this, now that you have learned coding in python. Your code will take in the step size and what is written in the diary and give out the real password.

----------------------------------------------------------------------
Input:
A list of two elements.
The first element will be a string consisting of only alphabets which is taken from the diary and the second element will be the step size.

Output:
A string denoting the password

----------------------------------------------------------------------
Sample input:
['ytKveh' 4]

Sample output:
upGrad

Explanation:
The password was 'upGrad'. Upon changing it by step of 4,
u became y,
p became t,
G became K,
r became v,
a became e,
d became h,
and thus what was written in the diary was ytKveh 

----------------------------------------------------------------------
Sample input:
['banana', 7]

Sample output:
utgtgt

Execution time limit

Default.

6 days ago in Python by Vaibhav
• 130 points
85 views

1 answer to this question.

0 votes

Hi @Vaibhav! In such a case what you can do is, 

ask the user for the password(which will be in the string format)

take each letter of the string and convert it into a character and use the ord() which will return its Unicode.

To this Unicode, you can add the count value and convert it back to a string.

Finally, print it'

You can use the following code:

password = input("Enter the password")
count = input("Enter the count")
final_pass = ""
for x in list(password):
    y = chr(ord(x) + count)
    final_pass = final_pass + y
print(final_pass)
answered 3 days ago by Kalgi
• 45,780 points

Related Questions In Python

0 votes
1 answer

Python join: why is it string.join(list) instead of list.join(string)?

950down voteaccepted It's because any iterable can be ...READ MORE

answered May 15, 2018 in Python by ariaholic
• 7,340 points
50 views
0 votes
1 answer

Python join: why is it string.join(list) instead of list.join(string)?

This is because join is a "string" ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 56,960 points
81 views
0 votes
2 answers

Finding the index of a character in python string

You can use word.find('o') as well to ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
131 views
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
2,631 views
0 votes
1 answer

Replace First and Last Word of String in the Most Pythonic Way

import re a = " this is a ...READ MORE

answered Aug 22, 2018 in Python by ariaholic
• 7,340 points
60 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 400 views
+7 votes
8 answers

Difference for string comparison in Python: 'is' vs. ==

If we use "==" means both variables ...READ MORE

answered Sep 3, 2018 in Python by Parul Raheja
498 views