SlideShare a Scribd company logo
1 of 9
Download to read offline
please help in python!!! (I have my code written below but i dont know if its correct)
main py code:
# Victor Carrillo
# March
# Obj; ENCRYpT AND DECRYPT RAHHHHH
import check_input
def menu():
""" Displays a menu for the user to interact with
Returns:
the users choice
"""
print("Secret Decoder Elden Ring: ")
print("1. Encrypt")
print("2. Decrypt")
return check_input.get_int_range("Enter choice: ", 1, 2)
def main():
while True:
choice = menu()
if choice == 1:
print("Enter encryption type: ")
print("1. Atbash")
print("2. Ceasar")
return check_input.get_int_range("Enter choice: ", 1, 2)
if choice == 2:
print("Enter decryption type: ")
print("1. Atbash")
print("2. Caesar")
main()
cihpherpy:
#dont use encrypt and decrypt in main
def __init__(self):
self.alpha = ["A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z"]
def encrypt_message(self, message):
message = alpha.upper()
while True:
if message == A:
encrypt_message(self, message)
elif message == B:
encrypt_message(self, message)
elif message == C:
encrypt_message(self, message)
elif message == D:
encrypt_message(self, message)
elif message == E:
encrypt_message(self, message)
elif message == F:
encrypt_message(self, message)
elif message == G:
encrypt_message(self, message)
elif message == H:
encrypt_message(self, message)
elif message == I:
encrypt_message(self, message)
elif message == J:
encrypt_message(self, message)
elif message == K:
encrypt_message(self, message)
elif message == L:
encrypt_message(self, message)
elif message == M:
encrypt_message(self, message)
elif message == N:
encrypt_message(self, message)
elif message == O:
encrypt_message(self, message)
elif message == P:
encrypt_message(self, message)
elif message == Q:
encrypt_message(self, message)
elif message == R:
encrypt_message(self, message)
elif message == S:
encrypt_message(self, message)
elif message == T:
encrypt_message(self, message)
elif message == U:
encrypt_message(self, message)
elif message == V:
encrypt_message(self, message)
elif message == W:
encrypt_message(self, message)
elif message == X:
encrypt_message(self, message)
elif message == Y:
encrypt_message(self, message)
elif message == Z:
encrypt_message(self, message)
def decrypt_message(self, message):
message = alpha.upper()
for i in range(len(message)):
def _encrypt_letter(self, letter):
def _decrypt_letter(self, letter):
cesaer cipher py:
def __init__(self, shift):
def _encrypt_letter(self, letter):
def _decrypt_letter(self, letter):
check input py:
""" Set of functions to validate user input.
Written by: Shannon Cleary
Date: Fall 2022
Functions:
get_int(prompt) - returns a valid integer (positive or negative).
get_positive_int(prompt) - returns a valid positive (>=0) integer.
get_int_range(prompt, low, high) - returns a valid integer within the inclusive range.
get_float(prompt) - returns a valid decimal value.
get_yes_no(prompt) - returns a valid yes/no input.
Usage: in your program, import the check_input module. Then call one of the methods using
check_input.
Example Usage:
import check_input
val = check_input.get_int("Enter #:")
print(val)
"""
def get_int(prompt):
"""Repeatedly takes in and validates user's input to ensure that it is an integer.
Args:
prompt: string to display to the user to prompt them to enter an input.
Returns:
The valid positive integer input.
"""
val = 0
valid = False
while not valid:
try:
val = int(input(prompt))
valid = True
except ValueError:
print("Invalid input - should be an integer.")
return val
def get_positive_int(prompt):
"""Repeatedly takes in and validates user's input to ensure that it is a positive (>= 0) integer.
Args:
prompt: string to display to the user to prompt them to enter an input.
Returns:
The valid integer input.
"""
val = 0
valid = False
while not valid:
try:
val = int(input(prompt))
if val >= 0:
valid = True
else:
print("Invalid input - should not be negative.")
except ValueError:
print("Invalid input - should be an integer.")
return val
def get_int_range(prompt, low, high):
"""Repeatedly takes in and validates user's input to ensure that it is an integer within the
specified range.
Args:
prompt: string to display to the user to prompt them to enter an input.
low: lower bound of range (inclusive)
high: upper bound of range (inclusive)
Returns:
The valid integer input within the specified range.
"""
val = 0
valid = False
while not valid:
try:
val = int(input(prompt))
if val >= low and val <= high:
valid = True
else:
print("Invalid input - should be within range " + str(low) + "-" + str(high) + ".")
except ValueError:
print("Invalid input - should be an integer.")
return val
def get_float(prompt):
"""Repeatedly takes in and validates user's input to ensure that it is a float.
Args:
prompt: string to display to the user to prompt them to enter an input.
Returns:
The valid floating point input.
"""
val = 0
valid = False
while not valid:
try:
val = float(input(prompt))
valid = True
except ValueError:
print("Invalid input - should be a decimal value.")
return val
def get_yes_no(prompt):
"""Repeatedly takes in and validates user's input to ensure that it is a yes or a no answer.
Args:
prompt: string to display to the user to prompt them to enter an input.
Returns:
True if yes, False if no.
"""
valid = False
while not valid:
val = input(prompt).upper()
if val == "YES" or val == "Y":
return True
elif val == "NO" or val == "N":
return False
else:
print("Invalid input - should be a 'Yes' or 'No'.")
Secret Decoder Ring Write a program that allows the user to encrypt or decrypt messages using
different types of encryption methods. Encrypted messages will read from the console and then
written to a file called 'message.txt', and decrypted messages will be read from the 'message.txt'
file then displayed to the console. Implement the following class structure using Inheritance:
Cipher (cipher.py) - Implements the Atbash Cipher - is a substitution cipher where the encrypted
message is obtained by looking up each letter and finding the corresponding letter in a reversed
alphabet. The encoded letter can be found in one of two ways, either a parallel list look up (ex.
letter to encode = ' B ', location = 1 , encoded letter location = 1 , which is a ' Y '), or a calculated
position in the list (ex. letter to encode = ' B ', location = 1 , 25 - location = 24 , encoded letter
location = 24 , which is a ' Y '). 1. _init_(self) - initializes the alphabet attribute - make a list with
the letters A Z in it (alternatively, this could just be one big string with the letters A Z in it, since
a string is effectively a list). 2. encrypt_message(self, message) - convert the message to upper
case letters, then loop through the message string one character at a time, if it is a letter A Z ,
then call the encrypt_letter method, otherwise ignore the character. Build the encryption string
using the encrypted letters and ignored characters, and then return it (ie. leave all spaces,
punctuation, and numbers the same, only letters in the string will be encrypted). 3.
decrypt_message(self, message) - convert the message to upper case letters, then loop through
the message string one character at a time. Build the decryption string using the decrypted letters
in a manner similar to the encrypt_message method above. 4._encrypt_letter(self, letter) - look
up the letter in the alphabet to find its location. Use that location to calculate the position of the
encrypted letter in the manner described above, then return the encrypted letter.
5.__decrypt_letter(self, letter) - look up the letter in the alphabet to find its location. Use that
location to calculate the position of the decrypted letter in the manner described above, then
return the decrypted letter. CasesarCipher (caesar_cipher.py) - Implements a Caesar Cipher - is
another substitution cipher where the encrypted message is found by looking up each letter and
finding the corresponding letter in a shifted alphabet (ex. letter to encode = ' B ', location = 1 ,
shift value = 3 , location + shift value = 1 + 3 = 4 , encoded letter location = 4 , which is an ' E ').
If the shift value causes the encoded letter to be past the end of the alphabet, then it should wrap
around to the beginning (ex. letter to encode = ' X ', location = 23 , shift value = 3 , location +
shift value = 23 + 3 = 26 , encoded letter location = 26 , which is larger than 25 , subtract the
total number of letters in the alphabet to get the updated location, 26 26 = 0 , which is an ' A ').
Fxamnle alnhabet with a shift value of 3 : 1. extend the cipher class 2. _init_(self, shift) - call
super to initialize the alphabet, then set the shift value if it is a number, otherwise raise an
exception. 3._encrypt_letter(self, letter) - look up the letter in the alphabet to find its location.
Use that location to calculate the position of the encrypted letter in the manner described above,
then return the encrypted letter. 4._decrypt_letter(self, letter) - look up the letter in the alphabet
to find its location. Use that location to calculate the position of the decrypted letter in the
manner described above, then return the decrypted letter. Main (main.py): Have the user choose
to encrypt or decrypt a message, then have them choose an encryption/decryption method
(Atbash or Caesar cipher). If they chose to encrypt, then prompt them to enter a message to
encrypt, then write the encrypted message to the file 'message.txt'. If they choose to decrypt a
message, read the message from the file 'message.txt' and then display the decrypted message to
the console. If they choose to use a Caesar Cipher for either encryption or decryption, then
prompt the user to enter a shift value ( 0 25 ) . Enter shift value: 3 Encrypted message saved to
"message.txt". Encrypted message written to file: WKH VRXS LV SRLVRQHG! Secret
Decoder Ring: 1. Encrypt 2. Decrypt 2 Enter decryption type: 1. Atbash 2. Caesar 2 Enter shift
value: 3 Reading encrypted message from "message.txt". Decrypted message: THE SOUP IS
POISONED! Notes: 1. You should have 4 different files: cipher.py, caesar_cipher.py, main.py,
and check_input.py. 2. Check all user input (except for the message) for invalid values using
get_int_range. 3. Do not create any extra methods or attributes in your classes. 4. Please do not
create any global variables or use the attributes globally. Only access the attributes using the
class's methods (note: it's usually ok for the subclass to access the attributes of the superclass
directly, since they are also attributes of the subclass). 5. Use docstrings to document the classes,
and each of their methods. 6. Place your names, date, and a brief description of the program in a
comment block at the top of your main file. Place brief comments throughout your code. 7.
Thoroughly test your program before submitting: a. Make sure that the user input is validated. b.
Make sure that the encrypted messages are written to the file. c. Make sure that decrypted
messages are read from the file. d. Make sure that the encrypted/decrypted text is correct given
the type of encryption/decryption and the shift value (when caesar is used). e. Make sure that you
test letters that are at the end of the alphabet so that when caesar's shift value is applied, it does
not go out of bounds of the alphabet. f. Make sure that any spaces, punctuation, or numbers are
preserved in the encrypted/decrypted message (only letters need to be encrypted).
please help in python!!! (I have my code written below but i dont know.pdf

More Related Content

Similar to please help in python!!! (I have my code written below but i dont know.pdf

Current C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdfCurrent C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdf
shyamsunder1211
 
I need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdfI need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdf
shreeaadithyaacellso
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
Blake0FxCampbelld
 
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdfC++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
rahulfancycorner21
 

Similar to please help in python!!! (I have my code written below but i dont know.pdf (20)

GRADE 11 Chapter 5 - Python Fundamentals.pptx
GRADE 11 Chapter 5 - Python Fundamentals.pptxGRADE 11 Chapter 5 - Python Fundamentals.pptx
GRADE 11 Chapter 5 - Python Fundamentals.pptx
 
Current C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdfCurrent C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdf
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
I need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdfI need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdf
 
Linq and lambda
Linq and lambdaLinq and lambda
Linq and lambda
 
Strings
StringsStrings
Strings
 
Pointer
PointerPointer
Pointer
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
Intoduction to php strings
Intoduction to php  stringsIntoduction to php  strings
Intoduction to php strings
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
 
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdfC++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
IMP PPT- Python programming fundamentals.pptx
IMP PPT- Python programming fundamentals.pptxIMP PPT- Python programming fundamentals.pptx
IMP PPT- Python programming fundamentals.pptx
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 

More from pankajsingh316693

PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdfPLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
pankajsingh316693
 
Please help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdfPlease help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdf
pankajsingh316693
 
Please give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdfPlease give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdf
pankajsingh316693
 

More from pankajsingh316693 (20)

PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdfPLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
 
Please help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdfPlease help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdf
 
Please help with best magnification for- Duodenum - mucosa Duodenum -.pdf
Please help with best magnification for- Duodenum - mucosa Duodenum -.pdfPlease help with best magnification for- Duodenum - mucosa Duodenum -.pdf
Please help with best magnification for- Duodenum - mucosa Duodenum -.pdf
 
Please help What stage of the cell cycle is this cell- The nuclear mem.pdf
Please help What stage of the cell cycle is this cell- The nuclear mem.pdfPlease help What stage of the cell cycle is this cell- The nuclear mem.pdf
Please help What stage of the cell cycle is this cell- The nuclear mem.pdf
 
PLEASE HELP ME Use the Internet to identify three network firewalls-.pdf
PLEASE HELP ME  Use the Internet to identify three network firewalls-.pdfPLEASE HELP ME  Use the Internet to identify three network firewalls-.pdf
PLEASE HELP ME Use the Internet to identify three network firewalls-.pdf
 
Please help me with this Java programming question- Please find your o.pdf
Please help me with this Java programming question- Please find your o.pdfPlease help me with this Java programming question- Please find your o.pdf
Please help me with this Java programming question- Please find your o.pdf
 
Please help me with the above multiple choice questions- This is my la.pdf
Please help me with the above multiple choice questions- This is my la.pdfPlease help me with the above multiple choice questions- This is my la.pdf
Please help me with the above multiple choice questions- This is my la.pdf
 
PLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdf
PLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdfPLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdf
PLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdf
 
Please help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdf
Please help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdfPlease help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdf
Please help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdf
 
please help Data tableenter a zero-)(b) Prepare the statement of owner.pdf
please help Data tableenter a zero-)(b) Prepare the statement of owner.pdfplease help Data tableenter a zero-)(b) Prepare the statement of owner.pdf
please help Data tableenter a zero-)(b) Prepare the statement of owner.pdf
 
please help thanks Pedigree of a Family with Tay-Sachs Disease I II.pdf
please help  thanks  Pedigree of a Family with Tay-Sachs Disease I II.pdfplease help  thanks  Pedigree of a Family with Tay-Sachs Disease I II.pdf
please help thanks Pedigree of a Family with Tay-Sachs Disease I II.pdf
 
Please help How many pairs of homologous chromosomes are there in a c.pdf
Please help  How many pairs of homologous chromosomes are there in a c.pdfPlease help  How many pairs of homologous chromosomes are there in a c.pdf
Please help How many pairs of homologous chromosomes are there in a c.pdf
 
please help 9- The shoreline of the western Coromandel Peninsula is.pdf
please help   9- The shoreline of the western Coromandel Peninsula is.pdfplease help   9- The shoreline of the western Coromandel Peninsula is.pdf
please help 9- The shoreline of the western Coromandel Peninsula is.pdf
 
Please give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdfPlease give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdf
 
Please give an explanation if possible- thank you so much Singlet ox.pdf
Please give an explanation if possible- thank you so much   Singlet ox.pdfPlease give an explanation if possible- thank you so much   Singlet ox.pdf
Please give an explanation if possible- thank you so much Singlet ox.pdf
 
please fast answer Let X be a continuous random variable with cumulat.pdf
please fast answer  Let X be a continuous random variable with cumulat.pdfplease fast answer  Let X be a continuous random variable with cumulat.pdf
please fast answer Let X be a continuous random variable with cumulat.pdf
 
Please explain why you choose one of the four options as your answer-.pdf
Please explain why you choose one of the four options as your answer-.pdfPlease explain why you choose one of the four options as your answer-.pdf
Please explain why you choose one of the four options as your answer-.pdf
 
Please fill in the space complexity- Problem 2 -1 pt- The following ta.pdf
Please fill in the space complexity- Problem 2 -1 pt- The following ta.pdfPlease fill in the space complexity- Problem 2 -1 pt- The following ta.pdf
Please fill in the space complexity- Problem 2 -1 pt- The following ta.pdf
 
Please explain in detail so i can further my understanding of this top.pdf
Please explain in detail so i can further my understanding of this top.pdfPlease explain in detail so i can further my understanding of this top.pdf
Please explain in detail so i can further my understanding of this top.pdf
 
please explain the general environment for the following of the corpor.pdf
please explain the general environment for the following of the corpor.pdfplease explain the general environment for the following of the corpor.pdf
please explain the general environment for the following of the corpor.pdf
 

Recently uploaded

Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
Elizabeth Walsh
 

Recently uploaded (20)

Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 

please help in python!!! (I have my code written below but i dont know.pdf

  • 1. please help in python!!! (I have my code written below but i dont know if its correct) main py code: # Victor Carrillo # March # Obj; ENCRYpT AND DECRYPT RAHHHHH import check_input def menu(): """ Displays a menu for the user to interact with Returns: the users choice """ print("Secret Decoder Elden Ring: ") print("1. Encrypt") print("2. Decrypt") return check_input.get_int_range("Enter choice: ", 1, 2) def main(): while True: choice = menu() if choice == 1: print("Enter encryption type: ") print("1. Atbash") print("2. Ceasar") return check_input.get_int_range("Enter choice: ", 1, 2) if choice == 2: print("Enter decryption type: ") print("1. Atbash") print("2. Caesar") main() cihpherpy:
  • 2. #dont use encrypt and decrypt in main def __init__(self): self.alpha = ["A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z"] def encrypt_message(self, message): message = alpha.upper() while True: if message == A: encrypt_message(self, message) elif message == B: encrypt_message(self, message) elif message == C: encrypt_message(self, message) elif message == D: encrypt_message(self, message) elif message == E: encrypt_message(self, message) elif message == F: encrypt_message(self, message) elif message == G: encrypt_message(self, message) elif message == H: encrypt_message(self, message) elif message == I: encrypt_message(self, message)
  • 3. elif message == J: encrypt_message(self, message) elif message == K: encrypt_message(self, message) elif message == L: encrypt_message(self, message) elif message == M: encrypt_message(self, message) elif message == N: encrypt_message(self, message) elif message == O: encrypt_message(self, message) elif message == P: encrypt_message(self, message) elif message == Q: encrypt_message(self, message) elif message == R: encrypt_message(self, message) elif message == S: encrypt_message(self, message) elif message == T: encrypt_message(self, message) elif message == U:
  • 4. encrypt_message(self, message) elif message == V: encrypt_message(self, message) elif message == W: encrypt_message(self, message) elif message == X: encrypt_message(self, message) elif message == Y: encrypt_message(self, message) elif message == Z: encrypt_message(self, message) def decrypt_message(self, message): message = alpha.upper() for i in range(len(message)): def _encrypt_letter(self, letter): def _decrypt_letter(self, letter): cesaer cipher py: def __init__(self, shift): def _encrypt_letter(self, letter): def _decrypt_letter(self, letter): check input py: """ Set of functions to validate user input.
  • 5. Written by: Shannon Cleary Date: Fall 2022 Functions: get_int(prompt) - returns a valid integer (positive or negative). get_positive_int(prompt) - returns a valid positive (>=0) integer. get_int_range(prompt, low, high) - returns a valid integer within the inclusive range. get_float(prompt) - returns a valid decimal value. get_yes_no(prompt) - returns a valid yes/no input. Usage: in your program, import the check_input module. Then call one of the methods using check_input. Example Usage: import check_input val = check_input.get_int("Enter #:") print(val) """ def get_int(prompt): """Repeatedly takes in and validates user's input to ensure that it is an integer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid positive integer input. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) valid = True except ValueError: print("Invalid input - should be an integer.") return val def get_positive_int(prompt): """Repeatedly takes in and validates user's input to ensure that it is a positive (>= 0) integer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid integer input.
  • 6. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) if val >= 0: valid = True else: print("Invalid input - should not be negative.") except ValueError: print("Invalid input - should be an integer.") return val def get_int_range(prompt, low, high): """Repeatedly takes in and validates user's input to ensure that it is an integer within the specified range. Args: prompt: string to display to the user to prompt them to enter an input. low: lower bound of range (inclusive) high: upper bound of range (inclusive) Returns: The valid integer input within the specified range. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) if val >= low and val <= high: valid = True else: print("Invalid input - should be within range " + str(low) + "-" + str(high) + ".") except ValueError: print("Invalid input - should be an integer.") return val def get_float(prompt): """Repeatedly takes in and validates user's input to ensure that it is a float. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid floating point input. """
  • 7. val = 0 valid = False while not valid: try: val = float(input(prompt)) valid = True except ValueError: print("Invalid input - should be a decimal value.") return val def get_yes_no(prompt): """Repeatedly takes in and validates user's input to ensure that it is a yes or a no answer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: True if yes, False if no. """ valid = False while not valid: val = input(prompt).upper() if val == "YES" or val == "Y": return True elif val == "NO" or val == "N": return False else: print("Invalid input - should be a 'Yes' or 'No'.") Secret Decoder Ring Write a program that allows the user to encrypt or decrypt messages using different types of encryption methods. Encrypted messages will read from the console and then written to a file called 'message.txt', and decrypted messages will be read from the 'message.txt' file then displayed to the console. Implement the following class structure using Inheritance: Cipher (cipher.py) - Implements the Atbash Cipher - is a substitution cipher where the encrypted message is obtained by looking up each letter and finding the corresponding letter in a reversed alphabet. The encoded letter can be found in one of two ways, either a parallel list look up (ex. letter to encode = ' B ', location = 1 , encoded letter location = 1 , which is a ' Y '), or a calculated position in the list (ex. letter to encode = ' B ', location = 1 , 25 - location = 24 , encoded letter location = 24 , which is a ' Y '). 1. _init_(self) - initializes the alphabet attribute - make a list with the letters A Z in it (alternatively, this could just be one big string with the letters A Z in it, since a string is effectively a list). 2. encrypt_message(self, message) - convert the message to upper case letters, then loop through the message string one character at a time, if it is a letter A Z , then call the encrypt_letter method, otherwise ignore the character. Build the encryption string using the encrypted letters and ignored characters, and then return it (ie. leave all spaces, punctuation, and numbers the same, only letters in the string will be encrypted). 3. decrypt_message(self, message) - convert the message to upper case letters, then loop through the message string one character at a time. Build the decryption string using the decrypted letters
  • 8. in a manner similar to the encrypt_message method above. 4._encrypt_letter(self, letter) - look up the letter in the alphabet to find its location. Use that location to calculate the position of the encrypted letter in the manner described above, then return the encrypted letter. 5.__decrypt_letter(self, letter) - look up the letter in the alphabet to find its location. Use that location to calculate the position of the decrypted letter in the manner described above, then return the decrypted letter. CasesarCipher (caesar_cipher.py) - Implements a Caesar Cipher - is another substitution cipher where the encrypted message is found by looking up each letter and finding the corresponding letter in a shifted alphabet (ex. letter to encode = ' B ', location = 1 , shift value = 3 , location + shift value = 1 + 3 = 4 , encoded letter location = 4 , which is an ' E '). If the shift value causes the encoded letter to be past the end of the alphabet, then it should wrap around to the beginning (ex. letter to encode = ' X ', location = 23 , shift value = 3 , location + shift value = 23 + 3 = 26 , encoded letter location = 26 , which is larger than 25 , subtract the total number of letters in the alphabet to get the updated location, 26 26 = 0 , which is an ' A '). Fxamnle alnhabet with a shift value of 3 : 1. extend the cipher class 2. _init_(self, shift) - call super to initialize the alphabet, then set the shift value if it is a number, otherwise raise an exception. 3._encrypt_letter(self, letter) - look up the letter in the alphabet to find its location. Use that location to calculate the position of the encrypted letter in the manner described above, then return the encrypted letter. 4._decrypt_letter(self, letter) - look up the letter in the alphabet to find its location. Use that location to calculate the position of the decrypted letter in the manner described above, then return the decrypted letter. Main (main.py): Have the user choose to encrypt or decrypt a message, then have them choose an encryption/decryption method (Atbash or Caesar cipher). If they chose to encrypt, then prompt them to enter a message to encrypt, then write the encrypted message to the file 'message.txt'. If they choose to decrypt a message, read the message from the file 'message.txt' and then display the decrypted message to the console. If they choose to use a Caesar Cipher for either encryption or decryption, then prompt the user to enter a shift value ( 0 25 ) . Enter shift value: 3 Encrypted message saved to "message.txt". Encrypted message written to file: WKH VRXS LV SRLVRQHG! Secret Decoder Ring: 1. Encrypt 2. Decrypt 2 Enter decryption type: 1. Atbash 2. Caesar 2 Enter shift value: 3 Reading encrypted message from "message.txt". Decrypted message: THE SOUP IS POISONED! Notes: 1. You should have 4 different files: cipher.py, caesar_cipher.py, main.py, and check_input.py. 2. Check all user input (except for the message) for invalid values using get_int_range. 3. Do not create any extra methods or attributes in your classes. 4. Please do not create any global variables or use the attributes globally. Only access the attributes using the class's methods (note: it's usually ok for the subclass to access the attributes of the superclass directly, since they are also attributes of the subclass). 5. Use docstrings to document the classes, and each of their methods. 6. Place your names, date, and a brief description of the program in a comment block at the top of your main file. Place brief comments throughout your code. 7. Thoroughly test your program before submitting: a. Make sure that the user input is validated. b. Make sure that the encrypted messages are written to the file. c. Make sure that decrypted messages are read from the file. d. Make sure that the encrypted/decrypted text is correct given the type of encryption/decryption and the shift value (when caesar is used). e. Make sure that you test letters that are at the end of the alphabet so that when caesar's shift value is applied, it does not go out of bounds of the alphabet. f. Make sure that any spaces, punctuation, or numbers are preserved in the encrypted/decrypted message (only letters need to be encrypted).