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
How are the number of rows calculated.​
Eva8 [605]

Answer:

ROWS function

Explanation:

Hope this helped

6 0
2 years ago
Discuss the inte Generation of computer, Inlith
ch4aika [34]

Generations of Computers

The computers of today find their roots in the second half of the twentieth century. Later as time progressed, we saw many technological improvements in physics and electronics. This has eventually led to revolutionary developments in the hardware and software of computers. In other words, soon the computer started to evolve. Each such technological advancement marks a generation of computers.

3 0
3 years ago
Which of the following is the first step in the boot process? Select one: A. The BIOS checks that all devices are operational. B
dalvyx [7]

Answer:

D. The BIOS is activated by powering on the CPU.

Explanation:

The BIOS is activated by powering on the CPU is the first step in the boot process.

5 0
3 years ago
Who lives in a pineapple under the sea?
VashaNatasha [74]

Answer:

CCCCCC

Explanation:

4 0
3 years ago
Read 2 more answers
You can insert pictures,such as scanned photographs, line art, and artwork, into a presentation. (points : 2) true false
Lady bird [3.3K]
True, i have done this before in my presentation slides
5 0
3 years ago
Other questions:
  • The ____ shortcut keys remove character formatting. (points : 2) ctrl 0 (zero) ctrl i ctrl spacebar ctrl u
    8·2 answers
  • Walking paths across the part is represented by the equation why equals -4x - 6​
    9·1 answer
  • The 2 main types of copyright relevant to the recording industry?
    5·2 answers
  • You can access various sites on the WWW by using hyperlinks or by______. A. entering a key word for your search B. following dir
    12·2 answers
  • Brad Smith works for GHI Firm. GHI firm is a registered Broker-Dealer in State A, B and C and a registered IA in State A. Brad i
    10·1 answer
  • In cell F15, insert a function that will automatically display the word Discontinue if the value in cell D15 is less than 1500,
    6·1 answer
  • Georgenotfound??? question mark??
    15·2 answers
  • im in honors comupter science and one of my questions is evaluate 18% 7 does anyone know how to answer that
    6·1 answer
  • Why is it important to evaluate the website on which you plan to shop?
    13·1 answer
  • An organization requires secure configuration baselines for all platforms and technologies that are used. If any system cannot c
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!