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 may present a problem for Linux users?
motikmotik
Tendancy to crash hope that helped
6 0
3 years ago
Read 2 more answers
Taking phrases, sentences, or paragraphs of text from a source then using them without giving attribution is plagiarism. This in
lys-0071 [83]

Answer:

True, that would be plagiarism

8 0
2 years ago
One of the most common causes of fires in the home and workplace is: a. All of the answer choices b. Arson c. Candle d. Faulty e
solniwko [45]
Electricity is one of the most common causes of fire in homes and workplaces. Electrical accidents appear to be caused by a combination of two factors: 1. Unsafe equipment and/or installation; 2. Workplaces made unsafe by the environment

So the answer would be D)Faulty electricity
8 0
3 years ago
My laptop screen is flashing colors all of the sudden, how can I solve this problem? Also why is this happening is it software o
MatroZZZ [7]

Explanation:

To determine whether a display driver or app is causing the problem,check to see if Task Manager flickers. ... Then, based on that information, you'll need to update, rollback, or uninstall your displ

यह निर्धारित करने के लिए कि क्या कोई डिस्प्ले ड्राइवर या ऐप समस्या पैदा कर रहा है, यह देखने के लिए जांचें कि क्या कार्य प्रबंधक फ़्लिकर करता है। ... फिर, उस जानकारी के आधार पर, आपको अपने डिस्प्ले को अपडेट, रोलबैक या अनइंस्टॉल करना होगा

i think this can help you

7 0
3 years ago
plan and implement an appropriate research design to investigate your aims with due consideration of ethnics​
DanielleElmas [232]

Answer:

Join wev-euby-kcr join

8 0
2 years ago
Other questions:
  • Paul is a baker who wants to improve his recipe for muffins because they turn out with a greasy flavor. What ingredient should h
    10·2 answers
  • A compound document contains _______ from different applications.
    12·2 answers
  • How do you close a document but keep the word processing program open?
    11·2 answers
  • The TabIndex value assigned to a text box's identifying label must be _______________ for the text box's access key to work corr
    14·1 answer
  • Word's Help feature is useful if you need to quickly learn how to print a document
    14·1 answer
  • Linda is the education manager for a national coding service company. Once a month she holds a videoconference with all her codi
    14·1 answer
  • 15
    5·2 answers
  • Choose all the items that represent potential ways to find a job opening.
    14·1 answer
  • Please answer this simple (hard) question for me lol
    13·2 answers
  • Write pseudo code that performs the following: Ask a user to enter a number. If the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!