lab assignment 1.13 LAB: Introduction to Cyptography (classes/constructors) Cryptography is the practice of encryption. Information Security uses cryptography techniques to encrypt and decrypt data. A simple encryption method might take plaintext and mix up the letters using some predetermined pattern and then use that pattern to decrypt the data for reading. Ciphers are the algorithms used to put the data into its secret pattern and then systematically decrypt it for reading. This script is going to use a famous simple cipher called the Caesar Cipher. It is a substitution cipher where each letter in the text is 'shifted' in a certain number of places. It uses the alphabet as the primary pattern and then based on the shift number, it would shift all the letters and replace the alphabet with our pattern. For example, if our shift number was 3, then A would be replaced with D, if we performed a right shift. As an example: Text = "THE CAT IS VISIBLE AT MIDNIGHT" Ciphertext = "WKH FDW LV YLVLEOH DW PLGQLIJKW" The keys to decrypt this message are the shift number and the direction. The shift value can be any integer from 0 - 25. The above example uses shift = 3 and the shift direction is right or direction = 'r'. Complete the CipherTest class by adding a constructor to initialize a cipher item. The constructor should initialize the shift to 0, and the direction to 'r' for right shift. If the constructor is called with a shift value, and direction, the constructor should assign each instance attribute with the appropriate parameter value. Complete the following TODO's: (1) create input for text, shift value, and direction (use lower( )) to keep l and r lower case (2) create a cipher item and use the constructor with the above input values (3) use control structures to call shifttoright() if direction is right and call shifttoleft if direction is left. Make sure you print out the return encrypted message inside the control structures. We can create the encrypted text by using the ord ( ) function. This function will return an integer that represents the Unicode code point of the character. Character are represented by different values for upp/er and lower case so an 'a' returns the integer 97. By using the unicode value we can add and subtract our shift value represented by an integer. The given program accepts as input a text string as our message to be encrypted, a shift value, and a direction of 'l' for left and 'r' for right. The program creates a cipher item using the input values. The program outputs the encrypted message based on the shift value and the direction provided. Ex: If the input is text = "Cryptography is fun!", shift = 4, and direction = l. The output is: Ynulpkcnwldu eo bqjk   class CipherTest: # TODO: Define a constructor with parameters to #initialize instance attributes (shift = 0, direction = 'r', text = "Testing" ) #Shift to right function def shift_to_right(self): encrypted_Text = "" for i in range(len(self.text)): c = self.text[i] #Encrypt upper case if(c == ' '): encrypted_Text += ' ' elif (c.isupper()): encrypted_Text += chr((ord(c) + self.shift-65) % 26 + 65) #Encrypt lower case else: encrypted_Text += chr((ord(c) + self.shift-97) % 26 + 97) return encrypted_Text #Shift to left function def shift_to_left(self): encrypted_Text = "" for i in range(len(self.text)): c = self.text[i] #Encrypt upper case if(c == ' '): encrypted_Text += ' ' elif (c.isupper()): encrypted_Text += chr((ord(c) - self.shift-65) % 26 + 65) #Encrypt lower case else: encrypted_Text += chr((ord(c) - self.shift-97) % 26 + 97) return encrypted_Text   if __name__ == "__main__": # TODO: create input for text, shift value, and direction (use lower( ) to keep l and r lower case # TODO: create a cipher item and use the constructor with the above input values # TODO: use control structures to call shift_to_right() if direction is right and call shift_to_left if direction # is left. Make sure you print out the return encrypted message here.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

lab assignment

1.13 LAB: Introduction to Cyptography (classes/constructors)

Cryptography is the practice of encryption. Information Security uses cryptography techniques to encrypt and decrypt data. A simple encryption method might take plaintext and mix up the letters using some predetermined pattern and then use that pattern to decrypt the data for reading.

Ciphers are the algorithms used to put the data into its secret pattern and then systematically decrypt it for reading. This script is going to use a famous simple cipher called the Caesar Cipher. It is a substitution cipher where each letter in the text is 'shifted' in a certain number of places. It uses the alphabet as the primary pattern and then based on the shift number, it would shift all the letters and replace the alphabet with our pattern.

For example, if our shift number was 3, then A would be replaced with D, if we performed a right shift. As an example:

Text = "THE CAT IS VISIBLE AT MIDNIGHT" Ciphertext = "WKH FDW LV YLVLEOH DW PLGQLIJKW"

The keys to decrypt this message are the shift number and the direction. The shift value can be any integer from 0 - 25. The above example uses shift = 3 and the shift direction is right or direction = 'r'.

Complete the CipherTest class by adding a constructor to initialize a cipher item. The constructor should initialize the shift to 0, and the direction to 'r' for right shift. If the constructor is called with a shift value, and direction, the constructor should assign each instance attribute with the appropriate parameter value.

Complete the following TODO's: (1) create input for text, shift value, and direction (use lower( )) to keep l and r lower case (2) create a cipher item and use the constructor with the above input values (3) use control structures to call shifttoright() if direction is right and call shifttoleft if direction is left. Make sure you print out the return encrypted message inside the control structures.

We can create the encrypted text by using the ord ( ) function. This function will return an integer that represents the Unicode code point of the character. Character are represented by different values for upp/er and lower case so an 'a' returns the integer 97. By using the unicode value we can add and subtract our shift value represented by an integer.

The given program accepts as input a text string as our message to be encrypted, a shift value, and a direction of 'l' for left and 'r' for right. The program creates a cipher item using the input values. The program outputs the encrypted message based on the shift value and the direction provided.

Ex: If the input is text = "Cryptography is fun!", shift = 4, and direction = l.
The output is: Ynulpkcnwldu eo bqjk

 

class CipherTest:
# TODO: Define a constructor with parameters to
#initialize instance attributes (shift = 0, direction = 'r', text = "Testing" )

#Shift to right function
def shift_to_right(self):
encrypted_Text = ""
for i in range(len(self.text)):
c = self.text[i]
#Encrypt upper case
if(c == ' '):
encrypted_Text += ' '
elif (c.isupper()):
encrypted_Text += chr((ord(c) + self.shift-65) % 26 + 65)
#Encrypt lower case
else:
encrypted_Text += chr((ord(c) + self.shift-97) % 26 + 97)

return encrypted_Text

#Shift to left function
def shift_to_left(self):
encrypted_Text = ""
for i in range(len(self.text)):
c = self.text[i]
#Encrypt upper case
if(c == ' '):
encrypted_Text += ' '
elif (c.isupper()):
encrypted_Text += chr((ord(c) - self.shift-65) % 26 + 65)
#Encrypt lower case
else:
encrypted_Text += chr((ord(c) - self.shift-97) % 26 + 97)

return encrypted_Text

 

if __name__ == "__main__":
# TODO: create input for text, shift value, and direction (use lower( ) to keep l and r lower case

# TODO: create a cipher item and use the constructor with the above input values

# TODO: use control structures to call shift_to_right() if direction is right and call shift_to_left if direction
# is left. Make sure you print out the return encrypted message here.

 

G entry level
* Home
Content
zy Section 1.1
(229) ITS12 X
G LAB: All per X
b Answered:
G 1.13 LAB: In x
Contact Us
M Inbox (7,71 ×
+
i learn.zybooks.com/zybook/CYB_135_54915392/chapter/1/section/13
= zyBooks My library > CYB/135: Object-Oriented Security Scripting home > 1.13: LAB: Introduction to Cyptography (classes/constructors)
E zyBooks catalog
? Help/FAQ
Kenneth Schultz -
direction provided.
Ex: If the input is text = "Cryptography is fun!", shift = 4, and direction = 1.
The output is:
Ynulpkcnwldu eo bąjk
346682.2019644.qx3zqy7
LAB
1.13.1: LAB: Introduction to Cyptography (classes/constructors)
0/10
АCTIVITY
main.py
Load default template...
32
else:
33
encrypted_Text += chr((ord(c) - self.shift-97) % 26 + 97)
34
35
return encrypted_Text
36
37
38
39 if
_main_":|
name
# TODO: create input for text, shift value, and direction (use Lower( ) to keep l and r lower case
==
40
41
42
# TODO: create a cipher item and use the constructor with the above input values
43
# TODO: use control structures to call shift_to_right() if direction is right and call shift_to_left if direction
# is left.
44
45
Make sure you print out the return encrypted message here.
46
47
48
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
Develop mode
Submit mode
second box.
Enter program input (optional)
If your code requires input values, provide them here.
3:43 AM
O Type here to search
75°F Rain to stop
9/16/2021
Transcribed Image Text:G entry level * Home Content zy Section 1.1 (229) ITS12 X G LAB: All per X b Answered: G 1.13 LAB: In x Contact Us M Inbox (7,71 × + i learn.zybooks.com/zybook/CYB_135_54915392/chapter/1/section/13 = zyBooks My library > CYB/135: Object-Oriented Security Scripting home > 1.13: LAB: Introduction to Cyptography (classes/constructors) E zyBooks catalog ? Help/FAQ Kenneth Schultz - direction provided. Ex: If the input is text = "Cryptography is fun!", shift = 4, and direction = 1. The output is: Ynulpkcnwldu eo bąjk 346682.2019644.qx3zqy7 LAB 1.13.1: LAB: Introduction to Cyptography (classes/constructors) 0/10 АCTIVITY main.py Load default template... 32 else: 33 encrypted_Text += chr((ord(c) - self.shift-97) % 26 + 97) 34 35 return encrypted_Text 36 37 38 39 if _main_":| name # TODO: create input for text, shift value, and direction (use Lower( ) to keep l and r lower case == 40 41 42 # TODO: create a cipher item and use the constructor with the above input values 43 # TODO: use control structures to call shift_to_right() if direction is right and call shift_to_left if direction # is left. 44 45 Make sure you print out the return encrypted message here. 46 47 48 Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the Develop mode Submit mode second box. Enter program input (optional) If your code requires input values, provide them here. 3:43 AM O Type here to search 75°F Rain to stop 9/16/2021
G entry level
* Home
Content
zy Section 1.1
(229) ITS12 X
G LAB: All per X
b Answered:
G 1.13 LAB: In x
Contact Us
M Inbox (7,71 ×
+
i learn.zybooks.com/zybook/CYB_135_54915392/chapter/1/section/13
= zyBooks My library > CYB/135: Object-Oriented Security Scripting home > 1.13: LAB: Introduction to Cyptography (classes/constructors)
E zyBooks catalog
? Help/FAQ
Kenneth Schultz -
direction provided.
Ex: If the input is text = "Cryptography is fun!", shift = 4, and direction = 1.
The output is:
Ynulpkcnwldu eo bąjk
346682.2019644.qx3zqy7
LAB
1.13.1: LAB: Introduction to Cyptography (classes/constructors)
0/10
АCTIVITY
main.py
Load default template...
1 class CipherTest:
# TODO: Define a constructor with parameters to
#initialize instance attributes (shift = 0, direction = 'r', text = "Testing" )
2
3
4
#Shift to right function
def shift_to_right(self):
encrypted_Text = ""
for i in range(len(self.text)):
c = self.text[i]
#Encrypt upper case
if(c == ''):
encrypted_Text += '
elif (c.isupper()):
encrypted_Text += chr((ord(c) + self.shift-65) % 26 + 65)
#Encrypt lower case
else:
7
8
10
11
12
13
14
15
16
17
encrypted_Text += chr((ord(c) + self.shift-97) % 26 + 97)
18
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
Develop mode
Submit mode
second box.
Enter program input (optional)
If your code requires input values, provide them here.
3:43 AM
O Type here to search
75°F Rain to stop
9/16/2021
Transcribed Image Text:G entry level * Home Content zy Section 1.1 (229) ITS12 X G LAB: All per X b Answered: G 1.13 LAB: In x Contact Us M Inbox (7,71 × + i learn.zybooks.com/zybook/CYB_135_54915392/chapter/1/section/13 = zyBooks My library > CYB/135: Object-Oriented Security Scripting home > 1.13: LAB: Introduction to Cyptography (classes/constructors) E zyBooks catalog ? Help/FAQ Kenneth Schultz - direction provided. Ex: If the input is text = "Cryptography is fun!", shift = 4, and direction = 1. The output is: Ynulpkcnwldu eo bąjk 346682.2019644.qx3zqy7 LAB 1.13.1: LAB: Introduction to Cyptography (classes/constructors) 0/10 АCTIVITY main.py Load default template... 1 class CipherTest: # TODO: Define a constructor with parameters to #initialize instance attributes (shift = 0, direction = 'r', text = "Testing" ) 2 3 4 #Shift to right function def shift_to_right(self): encrypted_Text = "" for i in range(len(self.text)): c = self.text[i] #Encrypt upper case if(c == ''): encrypted_Text += ' elif (c.isupper()): encrypted_Text += chr((ord(c) + self.shift-65) % 26 + 65) #Encrypt lower case else: 7 8 10 11 12 13 14 15 16 17 encrypted_Text += chr((ord(c) + self.shift-97) % 26 + 97) 18 Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the Develop mode Submit mode second box. Enter program input (optional) If your code requires input values, provide them here. 3:43 AM O Type here to search 75°F Rain to stop 9/16/2021
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education