def Introduction(): ''' setting the intro menu ''' global intro2 # accessing global variable pygame.display.set_caption("Line Segment Intersection Visualisation Tool") while intro2 == False: # initial loop and setting the exit src.display.fill((0, 0, 0)) # setting the display colour # pygame method, iterates over the events in pygame to determine what we are doing with every event for event in pygame.event.get(): if event.type == pygame.QUIT: # this one quits pygame.quit() # putting the quit pygame method exit() # takes the user from GUI to the script for exiting if event.type == pygame.KEYUP: # Here is to tell the computer to recognise if a keybord key is pressed if event.key == pygame.K_ESCAPE: # if that keyboard key is ESC exit() # call for the exit function. font = pygame.font.Font(src.bitterfont, 21) # creating font with size # creating font pygame text object with size, colour and text renderedText = font.render( "Welcome to the Line Segment Intersection Visualisation Tool", True, (255, 255, 255)) # displaying text on the screen, pos is the position of where it should appear surface = pygame.display.get_surface() xwidth = (surface.get_width() / 2) - 60 twidth = surface.get_width() / 2 - renderedText.get_width() / 2 src.display.blit(renderedText, (twidth, 140)) hlp.Button("Continue", xwidth, 200, 120, 30, StartIntro2) # continue button hlp.Button("Exit", xwidth, 250, 120, 30, sys.exit) # updates the screen every turn pygame.display.flip() # will not run more than 10 frames per second src.clock.tick(60) Introduction2() # calls back the introduction function
def Introduction(): ''' setting the intro menu ''' global intro2, secret # accessing global variable pygame.display.set_caption("Hashing Algorithms Visualization Tool") while intro2 == False: # initial loop and setting the exit src.display.fill((0,0,0)) # setting the display colour src.display.blit(src.bg,(0,0)) ## this is a pygame method allowing us to paste objects into the screen. it takes pixel location and the object as arguments. # pygame method, iterates over the events in pygame to determine what we are doing with every event for event in pygame.event.get(): if event.type == pygame.QUIT: # this one quits pygame.quit() # putting the quit pygame method exit() # takes the user from GUI to the script for exiting if event.type == pygame.KEYUP: # Here is to tell the computer to recognise if a keybord key is pressed. if event.key == pygame.K_ESCAPE: # if that keyboard key is ESC exit() # call for the exit function. if event.type == pygame.MOUSEBUTTONDOWN: # starting the initial loop with first game events, i.e. quit and mouse button if event.button == 1: # pygame method defining the button in the GUI pos = pygame.mouse.get_pos() # displays the mouse position on the screen # starting the initial loop with first game events, ie. quit and mouse button if xwidth < pos[0] < xwidth+120 and 350 < pos[1] < 350+30: srctTxt = hlp.InsertSecret("Text for Encription:") # getting the number of lines if srctTxt != "": # if the string is not empty try: # input gives string so this one turns it into an integer secret = srctTxt StartIntro2() except: # if that is not happening secret = "N/A" font = pygame.font.Font(src.bitterfont, 21) # creating font with size # creating font pygame text object with size, colour and text renderedText = font.render("Welcome to the Hashing Algorithms Comparison Tool", True, (255,255,255)) # displaying text on the screen, pos is the position of where it should appear surface = pygame.display.get_surface() xwidth = (surface.get_width()/2) - 60 twidth = surface.get_width() /2 - renderedText.get_width()/2 src.display.blit(renderedText, (twidth,140)) hlp.Button("Insert Message", xwidth, 350, 120, 30, None) hlp.Button("Continue", xwidth, 400, 120, 30, StartIntro2) # continue button hlp.Button("Exit", xwidth, 450, 120, 30, sys.exit) # updates the screen every turn pygame.display.flip() # will not run more than 10 frames per second src.clock.tick(60) Introduction2() # calls back the introduction function
def test_Button(): pos = pygame.mouse.get_pos() # checking if pygame is working click = pygame.mouse.get_pressed() if hlp.Button("mock", 345, 531, 112, 45, src.ClearActive): # asserting whether the function is working and the button is working as required assert src.ClearActive()
def Introduction2(): ''' Setting the algorithms menu ''' display = pygame.display.set_mode( (1280, 550), pygame.FULLSCREEN | pygame.DOUBLEBUF) # seting the display # pygame method for captioning pygame.display.set_caption("Line Segment Intersection Visualisation Tool") src.ChangeColour() # calling change colour function while True: # stating the loop display.fill((0, 0, 0)) # setting the display colour # pygame method, iterates over the events in pygame to determine what we are doing with every event for event in pygame.event.get(): if event.type == pygame.QUIT: # this one quits pygame.quit() # putting the quit pygame method exit() # takes the user from GUI to the script for exiting if event.type == pygame.KEYUP: # Here is to tell the computer to recognise if a keybord key is pressed if event.key == pygame.K_ESCAPE: # if that keyboard key is ESC exit() # call for the exit function surface = pygame.display.get_surface() xwidth = (surface.get_width() / 2) - 125 pygame.draw.rect(display, hlp.button_colour, (xwidth - 7, 85, 264, 450), 3) v1 = hlp.ButtonWithReturn("Brute-Force Algorithm", xwidth, 90, 250, 30, 1) # positioning function buttons v2 = hlp.ButtonWithReturn("Bentley-Ottmann Algorithm", xwidth, 190, 250, 30, 2) # positioning function buttons v3 = hlp.ButtonWithReturn("Shamos-Hoey Algorithm", xwidth, 290, 250, 30, 3) # positioning function buttons v4 = hlp.ButtonWithReturn("Efficiency Comparison", xwidth, 390, 250, 30, 4) # positioning function buttons v5 = hlp.ButtonWithReturn("Efficiency Comparison 2", xwidth, 490, 250, 30, 5) # positioning function buttons hlp.Button("Exit to Desktop", xwidth, 590, 250, 30, sys.exit) # adding an exit button # if any is chosen, break the loop and go to the choice if v1 > 0 or v2 > 0 or v3 > 0 or v4 > 0 or v5 > 0: break pygame.display.flip() # updates the screen every turn src.clock.tick(60) # will not run more than 10 frames per second if v1 > 0: # calling for choice functions to go for src.BruteForceMain() # calling for choice functions to go for elif v2 > 0: # calling for choice functions to go for src.BentleyMain() # calling for choice functions to go for elif v3 > 0: # calling for choice functions to go for src.ShamosHoeyMain() # calling for choice functions to go for elif v4 > 0: # calling for choice functions to go for src.Efficiency() # calling for choice functions to go for elif v5 > 0: src.Efficiency2()
def Introduction2(): ''' Setting the algorithms menu ''' display = pygame.display.set_mode((1280, 550),pygame.FULLSCREEN | pygame.DOUBLEBUF) # seting the display # pygame method for captioning pygame.display.set_caption("Hashing Comparison Tool") #src.ChangeColour() # calling change colour function while True: # stating the loop display.fill((0,0,0)) # setting the display colour src.display.blit(src.bg,(0,0)) # this is a pygame method allowing us to paste objects into the screen. it takes pixel location and the object as arguments. # pygame method, iterates over the events in pygame to determine what we are doing with every event for event in pygame.event.get(): if event.type == pygame.QUIT: # this one quits pygame.quit() # putting the quit pygame method exit() # takes the user from GUI to the script for exiting if event.type == pygame.KEYUP: # Here is to tell the computer to recognise if a keybord key is pressed. if event.key == pygame.K_ESCAPE: # if that keyboard key is ESC exit() # call for the exit function. surface = pygame.display.get_surface() xwidth = (surface.get_width()/2) - 125 pygame.draw.rect(display, hlp.button_colour, (xwidth-7, 85, 264, 395), 3) v1 = hlp.ButtonWithReturn("MD5 Algorithm", xwidth, 90, 250, 30, 1) # positioning function buttons v2 = hlp.ButtonWithReturn("SHA1 Algorithm", xwidth, 190, 250, 30, 2) # positioning function buttons v3 = hlp.ButtonWithReturn("SHA256 Algorithm", xwidth, 290, 250, 30, 3) # positioning function buttons #v4 = hlp.ButtonWithReturn("Efficiency Comparison",xwidth, 390, 250, #30, 4) # positioning function buttons hlp.Button("Exit to Desktop", xwidth, 390, 250, 30, sys.exit) # adding an exit button if v1 > 0 or v2 > 0 or v3 > 0: # if any is chosen, break the loop and go to the choice break pygame.display.flip() # updates the screen every turn src.clock.tick(60) # will not run more than 10 frames per second if v1 > 0: # calling for choice functions to go for src.dspMd5() # calling for choice functions to go for elif v2 > 0: # calling for choice functions to go for src.dspSHA1() # calling for choice functions to go for elif v3 > 0: # calling for choice functions to go for src.dspSHA256() # calling for choice functions to go for
def dspMd5(): pygame.display.set_caption("MD5 Algorithm") # adding a caption display = pygame.display.set_mode((1280, 550), pygame.FULLSCREEN) effc = timeit.Timer(functools.partial(md5.md5, intro.secret)) efcTime = effc.timeit(15) effcsha1 = timeit.Timer(functools.partial(sha1.sha1, intro.secret)) efcTimesha1 = effc.timeit(15) effcSHA2 = timeit.Timer(functools.partial(sha256.sha256, intro.secret)) efcTimeSHA2 = effc.timeit(15) m = max(efcTime, efcTimesha1, efcTimeSHA2) efcMD5 = (efcTime / m) * 250 efcSHA1 = (efcTimesha1 / m) * 250 efcSHA2 = (efcTimeSHA2 / m) * 250 while True: # starting the game loop display.fill( (0, 0, 0) ) # pygame method to fill the screen, takes colours and a display object #display.blit(bg,(0,0)) # pygame method, iterates over the events in pygame to determine what we are doing with every event for event in pygame.event.get(): if event.type == pygame.QUIT: # this one quits pygame.quit() # putting the quit pygame method exit() # takes the user from GUI to the script for exiting if event.type == pygame.KEYUP: # Here is to tell the computer to recognise if a keybord key is pressed. if event.key == pygame.K_ESCAPE: # if that keyboard key is ESC exit() # call for the exit function. surface = pygame.display.get_surface() w, h = surface.get_size() loc1, loc2 = surface.get_size() w = (w / 2) - 60 h = (h / 2) - 200 hlp.AddText("Encrypted Text: " + intro.secret, (w - 150, h)) hlp.AddText( "Padded Text: " + str(md5.padding(intro.secret))[0:15] + "...", (w - 150, h + 40)) hlp.AddText("MD5 Hashing: " + md5.md5(intro.secret), (w - 150, loc2 - 175)) hlp.AddText( str(round(float(efcTime), 4)) + " seconds passed to execute this algorithm", (w - 150, 5 * loc2 / 6)) hlp.Button("Exit", 350, 5, 100, 30, sys.exit) back = hlp.ButtonWithReturn("Back", 900, 5, 100, 30, 1) if back > 0: # if back has a value, which means it has been clicked, stop the bigger loop that we started, i.e. the game loop, and break the game loop break pygame.draw.line(display, line_colour, (400, 250), (400, 500), 2) # pygame method, takes display, colour, and positions of where the lines start and end pygame.draw.line(display, line_colour, (350, 500), (950, 500), 2) hlp.AddText("MD5", (465, 510), hlp.white) hlp.AddText("SHA1", (615, 510), hlp.white) hlp.AddText("SHA256", (765, 510), hlp.white) hlp.AddText("0s", (395, 505), hlp.white) hlp.AddText(str(round(float(efcTime), 5)), (460, 230), hlp.white) hlp.AddText(str(round(float(efcTimesha1), 5)), (610, 230), hlp.white) hlp.AddText(str(round(float(efcTimeSHA2), 5)), (760, 230), hlp.white) bPos = 500 pygame.draw.rect(display, hlp.button_colour, (465, bPos - efcMD5, 50, efcMD5)) pygame.draw.rect(display, hlp.button_colour, (615, bPos - efcSHA1, 50, efcSHA1)) pygame.draw.rect(display, hlp.button_colour, (765, bPos - efcSHA2, 50, efcSHA2)) pygame.display.flip() # will not run more than 30 frames per second clock.tick(30) intro.Introduction2()