Implemented the Caesar class allowing Caesar

ciphers to be used
This commit is contained in:
2019-04-04 15:23:41 -04:00
parent 4db45dc50a
commit a78f4bf1aa

View File

@@ -15,38 +15,92 @@ class Caesar:
self.__shift = 0 #The amount that you need to shift each letter
#Sets shift and makes sure it is within the propper bounds
def __setShift(self, shiftAmount: int):
NotImplemented
self.__shift = shiftAmount % 26
#Sets the input string
def __setInputString(self, inputString: str):
NotImplemented
self.__inputString = inputString
#Encodes the inputString and stores the result in outputString
def __encode(self) -> str:
NotImplemented
temp = 0 #A temperary holder for the current working character
for cnt in range(0, len(self.__inputString)):
temp = ord(self.__inputString[cnt])
#If it is an upper case letter shift it and wrap if necessary
if(chr(temp).isupper()):
temp += self.__shift
#Wrap around if the letter is now out of bounds
if(temp < ord('A')):
temp += 26
elif(temp > ord('Z')):
temp -= 26
#If it is a lower case letter shift it and wrap if necessary
elif(chr(temp).islower()):
temp += self.__shift
#Wrap around if the letter is now out of bounds
if(temp < ord('a')):
temp += 26
elif(temp > ord('z')):
temp -= 26
#If it is whitespace, number, or punctuation just let it pass through
#Add it to the output string
self.__outputString += chr(temp)
return self.__outputString
#Decodes the inputString and stores the result in outputString
def __decode(self) -> str:
NotImplemented
temp = 0
for cnt in range(0, len(self.__inputString)):
temp = ord(self.__inputString[cnt])
#If it is an upper case letter shift it and wrap if necessary
if(chr(temp).isupper()):
temp -= self.__shift
if(temp < ord('A')):
temp += 26
elif(temp > ord('Z')):
temp -= 26
#If it is a lower case letter shift it and wrap if necessary
elif(chr(temp).islower()):
temp -= self.__shift
if(temp < ord('a')):
temp += 26
elif(temp > ord('z')):
temp -= 26
#If it is whitespace, number, or punctuation just let it pass through
#Add it to the output string
self.__outputString += chr(temp)
return self.__outputString
#Returns the inputString
def getInputString(self) -> str:
NotImplemented
return self.__inputString
#Returns the shift value
def getShift(self) -> int:
NotImplemented
return self.__shift
#Returns the outputString
def getOutputString(self) -> str:
NotImplemented
return self.__outputString
#Sets the shift and inputString and encodes the message
def encode(self, shiftAmount: int, input: str) -> str:
NotImplemented
def encode(self, shiftAmount: int, inputStr: str) -> str:
self.reset()
self.__setShift(shiftAmount)
self.__setInputString(inputStr)
return self.__encode()
#Sets the shift and inputString and decodes the message
def decode(self, shiftAmount: int, input: str) -> str:
NotImplemented
def decode(self, shiftAmount: int, inputStr: str) -> str:
self.reset()
self.__setShift(shiftAmount)
self.__setInputString(inputStr)
return self.__decode()
#Makes sure all of the variables are empty
def reset(self):
NotImplemented
self.__inputString = self.__outputString = ""
self.__shift = 0
#Returns the version of the library
@classmethod
def getVersion(cls) -> str:
NotImplemented
return cls.__version
#This will run the appropriate commands if this script is called stand alone instead of with the rest of the PypherStream program
if __name__ == "__main__":