From fd2d0eb50f6fa8779d737b196e53a8b9eb4e9f01 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 4 Apr 2019 15:24:57 -0400 Subject: [PATCH] Added tests for the Playfair Cipher --- testPypherStream.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/testPypherStream.py b/testPypherStream.py index ccbcbb5..0555f4c 100644 --- a/testPypherStream.py +++ b/testPypherStream.py @@ -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