1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ASHA 777 [7]
2 years ago
8

Program a substitution cipher in Python. Create 2 functions one for encryption and the other for decryption ( get the text as th

e parameter).
Computers and Technology
1 answer:
raketka [301]2 years ago
7 0

alphabet = "abcdefghijklmnopqrstuvwxyz"

def encrypt(txt):

   shift = int(input("Enter the shift: "))

   new_txt = ""

   for x in txt:

       if x in alphabet:

           if alphabet.index(x)+shift >= len(alphabet):

               new_txt += alphabet[(alphabet.index(x)+shift - len(alphabet))]

           else:

               new_txt += alphabet[alphabet.index(x)+shift]

       else:

           new_txt += x

   return new_txt

def decrpyt(txt):

   shift = int(input("Enter the known shift: "))

   new_txt = ""

   for x in txt:

       if x in alphabet:

           new_txt += alphabet[alphabet.index(x) - shift]

       else:

           new_txt += x

   return new_txt

print(encrypt("yellow dog."))

print(decrpyt("lryybj qbt."))

My code works with lowercase text only. If you need me to modify the code, I can do that. I tested my code with a shift of 13 in both the encryption and decryption. I hope this helps!

You might be interested in
If i hit the delete key three times what will be left
pogonyaev

Answer:

planation:

I got this

6 0
2 years ago
An office uses an application to assign work to its staff members. The application uses a binary sequence to represent each of 1
fenix001 [56]

Answer: I believe the answer is: A, 5.

Explanation:

6 0
3 years ago
A study guide can be created
choli [55]

Answer:

C, Both of these.

Explanation:

You can take notes either way. It's just your preference. Hope this helps :)

7 0
3 years ago
Read 2 more answers
You can use the ____ utility to zero in on the service or other program that is slowing down startup. 1. gpupdate 2. MSconfig 3.
Step2247 [10]
I'd say MSconfig, you can use that and view the 'processes' tab, but it will make you open up the task manager.
3 0
3 years ago
How much cell phone data does the average person use a month
azamat
It all depends on what you're doing online.
7 0
3 years ago
Other questions:
  • Write a function removeEvens to remove all the even numbers from input row array inRowArray which contains integer numbers. The
    15·1 answer
  • What is the best definition of the 7x7 rule for maximizing audience comprehension
    13·1 answer
  • Plis is a unit test !!!!!!! HelP ASAP only 30 mins left, will mark as brainliest
    8·1 answer
  • Assuming that we only support BEQ and ADD instructions, discuss how changes in the given latency of this resource affect the cyc
    7·1 answer
  • "background" software that helps the computer manage its own internal resources is called ________.
    5·1 answer
  • A string s is a circular shift of a string t if it matches when the the characters are circularly shifted by any number of posit
    9·1 answer
  • Kristi, an event planner, wants to store caterers’ names and contact information in an organized manner. Kristi will MOST LIKELY
    13·1 answer
  • Describe the scope of the variables in this code.
    8·2 answers
  • Which letter shows the ball when it has the maximum kinetic energy
    15·1 answer
  • Read the scenario below, and then choose the right type of computer for each person from the drop-down menus. Three of your frie
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!