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 cypheringdeciphering 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
Ideas from Python Programming in Context by Bradley N Miller and David L Ranum. Jmys & Bartlett Learning nd edition.
rotated. For the case of transposition, that no numeric key is need, a cero 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 alphabetkey like it was done in Project #
The class Cypher will look like this:
class Cypher:
def method:
def method
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 sbtClearCypher message, key that will return the cypher of message by performing substitution. This method uses rotateAlphabetkey 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:
# self: fixed and must be present in any declaration of a function.
# typeCypher: will be SBT for substitution or TRP for transposition. # myMessage: The message to cypherdecypher
# param: must be c for cyphering and d for deciphering.
# key: numeric value between to
# Returning value: message encrypteddecrypted. #######################################################
def cypher self, typeCypher, myMessage, param, key : if typeCypher SBT:
if param c:
return self.sbtClearCipher myMessage, key
elif param d:
return self.sbtCipherClear myMessage, key
else:
return Wrong Cypher
else:
if typeCypher TRP:
if param c:
return self.trpClearCipher myMessage
elif param d:
return self.trpCipherClear 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 inputinput message:
type inputtype of algorithm? SBTTRP if type SBT:
key intinputenter the rotation key else:
key
printfthe original message is: message
cyphered myCypher.cyphertype message, c key printthe cyphered message is: cyphered using type type clear myCypher.cyphertype cyphered, d key
printfThe clear message is clear using type type printalphabet: myCypher.getAlphabet
if type SBT:
printnew alphabet: myCypher.getNewAlphabet
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
