mirror of
https://bitbucket.org/Mattrixwv/pypherstream.git
synced 2025-12-06 18:43:58 -05:00
Added tests for the Playfair Cipher
This commit is contained in:
@@ -93,6 +93,52 @@ def caesarTest():
|
||||
if(passed):
|
||||
print("Caesar passed all tests")
|
||||
|
||||
#Test the Playfair cipher
|
||||
def playfairTest():
|
||||
#Setup the variables
|
||||
passed = True #Holds whether all tests have been passed
|
||||
keyword = "" #Holds the keyword for the cipher
|
||||
inputString = "" #Holds the string that will be encoded
|
||||
outputString = "" #Holds the string that will be decoded
|
||||
cipherString = "" #Holds the string that is returned from the cipher
|
||||
cipher = Playfair() #The cipher itself
|
||||
|
||||
#Test from wikipedia
|
||||
keyword = "Playfair Example"
|
||||
inputString = "Hide the gold in the tree stump"
|
||||
outputString = "BMODZBXDNABEKUDMUIXMMOUVIF"
|
||||
#Try encoding
|
||||
cipherString = cipher.encode(keyword, inputString)
|
||||
if(cipherString != outputString):
|
||||
print("Playfair failed the first encoding test")
|
||||
passed = False
|
||||
inputString = cipher.getInputString() #This makes sure input is a valid input for comparison later
|
||||
#Try decoding
|
||||
cipherString = cipher.decode(keyword, outputString)
|
||||
if(cipherString != inputString):
|
||||
print("Playfair failed the first decoding test")
|
||||
passed = False
|
||||
|
||||
#Slight alteration to test from wikipedia
|
||||
keyword = "Playfair Example"
|
||||
inputString = "Hide the gold in the tree stum"
|
||||
outputString = "BMODZBXDNABEKUDMUIXMMOUVIM"
|
||||
#Try encoding
|
||||
cipherString = cipher.encode(keyword, inputString)
|
||||
if(cipherString != outputString):
|
||||
print("Playfair failed the second encoding test")
|
||||
passed = False
|
||||
inputString = cipher.getInputString() #This makes sure input is a valid input for comparison later
|
||||
#Try decoding
|
||||
cipherString = cipher.decode(keyword, outputString)
|
||||
if(cipherString != inputString):
|
||||
print("Playfair failed the second decoding test")
|
||||
passed = False
|
||||
|
||||
#Print a message if there were no errors
|
||||
if(passed):
|
||||
print("Playfair passed all tests")
|
||||
|
||||
#Run all the appropriate tests in the right order
|
||||
if __name__ == "__main__":
|
||||
#Create a timer to check the time of the tests
|
||||
@@ -104,6 +150,12 @@ if __name__ == "__main__":
|
||||
timer.stop()
|
||||
print("It took " + timer.getString() + " to run this test\n")
|
||||
|
||||
#Test the Playfair cipher
|
||||
timer.start()
|
||||
playfairTest()
|
||||
timer.stop()
|
||||
print("It took " + timer.getString() + " to run this test")
|
||||
|
||||
|
||||
""" Results:
|
||||
Caesar passed all tests
|
||||
|
||||
Reference in New Issue
Block a user