Beginner question
Hi,
I'm struggling to figure out a way to encrypt this message. Ideally my program should work like this:
1. Ask for input of a word/message to encrypt. This could include letters and spaces.
2. Generate a number between 2 and 20 (i'll call it x for now)
3. Then randomly select characters of length x to put between each letter of the inputted message.
4. Print said encrypted message.
Issue is when I run the code it prints the same random letter and also does not remove any spaces. It also only uses the same length each time I run the code. Any suggestions on why this happens? Thank you.
import random
chars = 'abcdeifghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def ranchar():
y = random.randrange(2, 20)
for x in range(2, y):
ok = random.choice(chars)
return ok
phrase = input('Please enter the message you would like to encrypt: ')
print(ranchar().join(phrase))
Output:
tQhQeQ QqQuQiQcQkQ QbQrQoQwQnQ QfQoQxQ QjQuQmQpQsQ QoQvQeQrQ QtQhQeQ QlQaQzQyQ QdQoQg
Process finished with exit code 0