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
Which of the following are incorrect safety precautions for equipment operators? A. Drive equipment or vehicles on grades or roa
Zarrin [17]
Hello!

The correct answer would be: D. Should not exceed a vehicle's rated load or life capacity.

I hope you found this helpful! :)
3 0
3 years ago
Read 2 more answers
If the fluid level in a battery is below the separators<br> should be added but never add
geniusboy [140]
Never add tap water to your battery. ... Battery electrolyte levels should be just below the bottom of the vent well, about ½ - ¾ inch above the tops of the separators. Never let the electrolyte level to drop below the top of the plates.
7 0
3 years ago
Which of the following is likely the cause of the bass from a sound system rattling the windows on your car?
Andrei [34K]
The vibration of the sound system
4 0
3 years ago
Create a Python program in a file named loops1.py that does the following: a. Use a while loop to keep asking the user for input
Rashid [163]

Answer:

mystr = input("Enter a string ")

length = len(mystr)

while length<10:

   mystr = input("Enter a string ")

   length = len(mystr)

   if(length>=10):

       break

if len(mystr)%2==0:

   print(mystr.lower())

else:

   print(mystr.upper())

Explanation:

The variable mystr is used to save user's input which is received with the input function

A second variable length is used to save the length of the input string Using a while statement the user is continually prompted to enter a string while length is less than 10.

If length is greater or equal to 10. We check for even or odd using the modulo (%) operator.

We use lower() and upper() to change the case of the string

7 0
3 years ago
Read 2 more answers
Which of these can expose a computer to a virus? Check all that apply.
Rina8888 [55]

Answer:

downloads, websites, emails?

4 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following are you likely to find between multiple school buildings in a city wide school district?
    9·1 answer
  • For wired network cards that get their IP addresses through DHCP, what can be set manually?
    5·1 answer
  • Net Worth is equal to assets minus liabilities. Which event will have the greatest impact (positive or negative) on one's net wo
    9·1 answer
  • A computer program that senses when another computer is attempting to scan or access a computer or network is called an
    7·1 answer
  • A device receives a Transmission Control Protocol (TCP) packet. The device understands where the actual data payload begins. Whi
    15·1 answer
  • What is f(-3) for the function f(a)=-2a2-5a+4?​
    10·1 answer
  • A new employee has reported that print jobs are printing as garbled text. Which of the following is MOST likely the reason for t
    8·1 answer
  • While surfing online, Patricia checks her email and reads the latest messages. She then browsers a website and logs in a comment
    8·1 answer
  • 4.2 Lesson Practice​
    8·2 answers
  • For a parking application that lets you pay for parking via your phone, which of these is an example of a functional requirement
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!