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]
3 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]3 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
Anyone else 17 and still plays rblox xd?
Lerok [7]

Answer:

not me

Explanation:

Sorry :\

6 0
3 years ago
Read 2 more answers
(10 points) Make a user interface to get 3 points from the user which will be placed on the coordinate plane. Then write a Pytho
babymother [125]

Answer:

def cord_input():

Global coordinates

coordinates = {'x1': 0, 'y1': 0, 'x2':0, 'y2':0, 'x3':0, 'y3':0}

for key, i in enumerate(coordinates.keys()):

if i < 2:

index = 1

coordinates [key] = float(input(f"Enter {key} coordinate for point {index}: "))

elif i >= 2 and i < 4:

index = 2

coordinates [key] = float(input(f"Enter {key} coordinate for point {index}: "))

else:

index = 3

coordinates [key] = float(input(f"Enter {key} coordinate for point {index}: "))

def sides(p1, p2, p3):

nonlocal a, b, c

a = ((p2[0] - p1[0])**2) + ((p2[1] - p1[1])**2)

b = ((p3[0] - p2[0])**2) + ((p3[1] - p2[1])**2)

c = ((p3[0] -p1[0])**2) + ((p3[1] - p2[1])**2)

def is_right_triangle(p1, p2, p3):

sides(p1, p2, p3)

if a+b == c or b+c == a or a+c == b:

print(f"Sides {a}, {b} and {c}")

return True

else:

return False

def is_equilateral(p1, p2, p3):

sides(p1, p2, p3)

if a==b and b==c:

print(f"Sides {a}, {b} and {c}")

return True

else:

return False

cord_input()

Explanation:

The python code above defines four functions, cord_input (to input a global dictionary of coordinates), sides ( to calculate and assign the sides of the triangle), is_right_triangle ( to check if the coordinates are for a right-angle triangle), and is_equilateral for equilateral triangle check.

3 0
3 years ago
Which of the following BEST represents the relationship between physical fitness and exercise?
adoni [48]
Exercise is a subset of physical fittness
8 0
3 years ago
What are the example of dedicated computers?
Drupady [299]
A dedicated server is a single computer in a network reserved for serving the needs of the network. For example, some networks require that one computer be set aside to manage communications between all the other computers. A dedicated server could also be a computer that manages printer resources.
8 0
3 years ago
HELP ASAP
CaHeK987 [17]
The answer is B, e commerce. Have a good day
3 0
3 years ago
Other questions:
  • In a word processing program, the ribbon or menus contain the
    12·1 answer
  • Question 3 / 5
    9·1 answer
  • On a hard disk each track is divided into invisible wedge-shaped sections called _______
    15·1 answer
  • Which remote access configuration option should you choose if you want mobile users to be able to make a secure connection to th
    9·2 answers
  • Write a program that displays the following menu:
    8·1 answer
  • One of the prominent movies released in the 1950s is
    15·2 answers
  • Many contemporary languages allow two kinds of comments: one in which delimiters are used on both ends (multiple-line comments),
    7·1 answer
  • What are the words that make up a high-level programming language called?
    6·1 answer
  • When investigating the serial position curve, delaying the memory test for 30 seconds
    10·1 answer
  • A(n) Blank______ database model stores data in the form of logically related two-dimensional tables. Multiple choice question. w
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!