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
I am sorting data that is stored over a network connection. Based on the properties of that connection, it is extremely expensiv
Ann [662]

Answer: Provided in the explanation section

Explanation:

The question to this problem says;

Question:

I am sorting data that is stored over a network connection. Based on the properties of that connection, it is extremely expensive to "swap" two elements. But looping over the elements and looking at their values is very inexpensive. I want to minimize swaps above all other factors. Choose the sorting algorithm we studied that will perform the best:

ANSWER

1. Merge Sort

Because merge sort uses additional memory instead of swapping the elements.

2. Merge Sort and Quick Sort both can be used with multi processor.

cheers i hope this helps !!!

4 0
3 years ago
One foot equals 12 inches. Write a function named feet_to_inches that accepts a number of feet as an argument and returns the nu
fenix001 [56]

Answer:

def feet_to_inches( feet ):

      inches = feet * 12

      print(inches, "inches")

feet_to_inches(10)

Explanation:

The code is written in python.  The unit for conversion base on your question is that 1 ft = 12 inches. Therefore,

def feet_to_inches( feet ):

This code we define a function and pass the argument as feet which is the length in ft that is required when we call the function.

inches = feet * 12

Here the length in ft is been converted to inches by multiplying by 12.

print(inches, "inches")

Here we print the value in inches .

feet_to_inches(10)

Here we call the function and pass the argument in feet to be converted  

       

8 0
2 years ago
A fast food chain that wants to inform consumers about its latest dollar menu item will most likely use ___ to do so. ____ may i
Eva8 [605]
The correct answer is 1: B new tech and 2:C we can tell by the way businesses are incorporating things like social media like how Wendys got more popular because of their sassy tweets
3 0
3 years ago
Read 2 more answers
The capacity of a communication channel is measured in _______.
PSYCHO15rus [73]
<span>The capacity of a communication channel is measured in gb and gps.</span>
4 0
2 years ago
Read 2 more answers
What is wrong with the formula below? SUM(A1:A5)/SUM(B1:B5)
Triss [41]
I think the answer would be C
5 0
2 years ago
Read 2 more answers
Other questions:
  • If you want to conserve ink or toner, you can instruct PowerPoint to print ____ documents.
    10·1 answer
  • Software that manages and supports the resources of a computer is known as?
    10·1 answer
  • When you are working on an unsaved document on a PC, where is the document temporarily saved?
    5·1 answer
  • Host to IP address lookup and its reverse lookup option are very important network services for any size network. It is also how
    14·1 answer
  • Which is most likely a presentation file?
    8·1 answer
  • Suppose a process in Host C has a UDP socket with port number 6789. Suppose both Host A and Host B each send a UDP segment to Ho
    8·1 answer
  • . Write a C++ Code to get a multiline statement Str1 from a user with a ‘$’ as return character (Hint:
    6·1 answer
  • What is a good range for CPU usage to be considered running well?
    15·1 answer
  • Write program to read 10 random numbers, then find how many of them accept division by 4,
    6·1 answer
  • What is essential for a good study routine? Select four options.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!