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
IDENTIFYING VERBS THAT AGREE IN NUMBER WITH THEIR SUBJECTS For each of the following sentences, write the correct form of the ve
Novay_Z [31]

Hey there!

  • The word "<u>verb</u>" simply means <em>'description of an action, assert, or event that is made into the main purpose of your predicate in your judgement' </em>
  • Now that we have the definition of the word verb we can answer your question
  • "<em>Has</em>" is past tense but it is THIRD person present
  • "<em>Have</em>" is when you own something
<h2>Answer: HAS ✅</h2>

BECAUSE "I SAW last night"

Note: usually people read the sentence to themselves until it makes easier sense to them or use context clues in the sentence to answer the particular question(s)

Good luck on your assignment and enjoy your day!

~LoveYourselfFirst:)

6 0
3 years ago
Read 2 more answers
Question 12
AlladinOne [14]

Which is a multicast address ?

ans: 241.2.2.1

6 0
2 years ago
You have local administrative rights to your computer running windows 7. you cannot find some of the operating system files on y
ElenaW [278]
<span>a. uncheck ���hide protected operating system files��� in folder options</span>
6 0
2 years ago
Which code snippet calculates the sum of all the even elements in an array values? Group of answer choices int sum = 0; for (int
olganol [36]

Answer:

The second one:

int sum = 0; for (int i = 0; i < values.length; i++) { if ((values[i] % 2) == 0) { sum += values[i]; } }

5 0
3 years ago
20 POINTS!!!
Rina8888 [55]

Answer:

the third one

hope this helps

5 0
3 years ago
Other questions:
  • What are 2 ways that technology can negatively impact the environment.
    8·2 answers
  • The objective of ____ testing is to identify and eliminate execution errors that could cause a program to terminate abnormally,
    15·1 answer
  • In 2011 a program named Watson running on an IBM supercomputer
    12·1 answer
  • Your program will search for prime numbers. You will first ask the user for the range of values to search, and use for loops to
    6·1 answer
  • a pair of shoes is on sale for 15% off with this discount customers will pay $9 if they buy the shoes ​
    14·1 answer
  • Nia is editing a row in an Access table. The row contains the Pencil icon on the left end of the record
    12·2 answers
  • PLZZZZZZZZZZZZZZZ HELP ME OUT!!!!! I SICK AND TIRED OF PEOPLE SKIPING MY QUESTION WHICH IS DUE TODAY PLZ ANSWER ALL OFIT!!!!
    10·1 answer
  • he superclass Student contains: a constructor that accepts a String corresponding to the name of the school the student attends
    15·1 answer
  • A large number of consecutive IP addresses are available starting at 198.16.0.0. Suppose that four organizations, Able, Baker, C
    11·1 answer
  • A _____ is the viewing area for a web page, which is much smaller on a phone than on a traditional desktop.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!