Question: In this project you will design and implement the Cypher class. It is mandatory to use classes. Detail description: To design a class to represent

In this project you will design and implement the Cypher class. It is mandatory to use classes.
Detail description:
To design a class to represent the idea of a cypher, it is necessary to consider the data cypher objects, which will be needed to fulfill its task of cyphering/deciphering a message. A cypher needs to know the alphabet, the type of algorithm, the message, if it is ciphering or deciphering, and a key.
The alphabet is constant, and it corresponds to the English alphabet plus a space. The type of algorithm will be TRP for transposition or SBT for substitution. The message will be the message to cipher or decipher. A parameter -c will tell the object to cypher, and a parameter of -d will tell the object to decipher. And, a numeric key, will be used for the substitution method to count the number of places the alphabet will be
1 Ideas from Python Programming in Context by Bradley N. Miller and David L. Ranum. Jmys & Bartlett Learning 2nd edition.
rotated. For the case of transposition, that no numeric key is need, a cero (0) could be used as parameter.
In addition to data, a class will provide methods for accessing some instances of data. For this project a user can use the method getAlphabet() to get the alphabet the object is using and getNewAlphabet() to get the alphabet the object is using for substitution. Is there any other get method you consider necessary to implement?
In this implementation it is not required to implement a method for generating a -new ordered alphabet/key, like it was done in Project # 5.
The class Cypher will look like this:
class Cypher:
def method1():
...
def method2()
......
The first method that all classes should provide is the constructor, which can be defined as the way data objects are created. To define the Cypher class with the constructor and the getters methods, you can do this:
class Cypher:
def __init__( self):
self.alphabet = 'abcdefghijklmnopqrstuvwxyz ' self.newAlphabet =''
def getAlphabet( self): return self.alphabet
def getNewAlphabet ( self): return self.newAlphabet
you have to complete the class Cypher by defining more getters if needed and by defining the necessary methods for cyphering and deciphering like sbtClear2Cypher ( message, key) that will return the cypher of message by performing substitution. This method uses rotateAlphabet(key) that will rotate the English alphabet according to a numeric key, generating a new alphabet for doing the substitution.
Besides getters, the class Cypher has another method accessible to a user, the method cypher() that will receive as a parameters: the type of cypher to be used (TRP or SBT), the message, if the parameter that specifies if it is cyphering -c or deciphering -d and, the numeric key. The cypher method looks like this:
####################################################### # name of the Function: cypher
# Purpose of the function: This function uses transposition or
# substitution for encrypting messages.
# parameters:
# 1. self: fixed and must be present in any declaration of a function.
# 2. typeCypher: will be SBT for substitution or TRP for transposition. # 3. myMessage: The message to cypher/de-cypher
# 4. param: must be -c for cyphering and -d for deciphering.
# 5. key: numeric value between 0 to 26
# Returning value: message encrypted/de-crypted. #######################################################
def cypher( self, typeCypher, myMessage, param, key) : if typeCypher =='SBT':
if param =='-c':
return self.sbtClear2Cipher( myMessage, key)
elif param ==-d:
return self.sbtCipher2Clear ( myMessage, key)
else:
return ('** Wrong Cypher **')
else:
if typeCypher =='TRP':
if param =='-c':
return self.trpClear2Cipher ( myMessage)
elif param ==-d:
return self.trpCipher2Clear ( myMessage)
else:
return ('** Wrong Cypher **')
else:
return ('** Wrong Cypher **')
After all the definitions of attributes and methods have been done, you will create an object of the class Cypher:
myCypher = Cypher ()
now you can start using the object myCypher in this way:
message = input('input message: ')
type = input(type of algorithm? SBT/TRP) if type ==SBT:
key = int(input(enter the rotation key )) else:
key =0
print(fthe original message is: {message})
cyphered = myCypher.cypher(type, message, '-c', key) print(the cyphered message is: {cyphered} using type {type}) clear = myCypher.cypher(type, cyphered, '-d', key)
print(f'The clear message is {clear} using type {type}) print('alphabet: '+ myCypher.getAlphabet())
if type ==SBT:
print('new alphabet: '+ myCypher.getNewAlphabet())

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!