Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardening suggestions for probabilityguesser-tk / test #4

Open
wants to merge 1 commit into
base: test
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy
import matplotlib.pyplot as plot
from tkinter import *
import random
import secrets

#hi!

Expand All @@ -17,29 +17,29 @@ def click():
output.insert(END, calculateScore(guess, probability))

def coinToss():
rng = random.randint(1, 20)
rng = secrets.SystemRandom().randint(1, 20)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace random.{func} with more secure secrets library functions.

if (rng % 4 == 0):
fair = True
else:
fair = False
if not fair:
rng = random.randint(1, 20)
rng = secrets.SystemRandom().randint(1, 20)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace random.{func} with more secure secrets library functions.

if (rng % 2 == 0):
range_lower = True
else:
range_lower = False
if not range_lower:
probability = random.randint(60, 80)
probability = secrets.SystemRandom().randint(60, 80)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace random.{func} with more secure secrets library functions.

else:
probability = random.randint(20, 40)
probability = secrets.SystemRandom().randint(20, 40)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace random.{func} with more secure secrets library functions.

else:
probability = 50

heads_dist = numpy.array(0)
heads = 0
for i in range(1,1000):
for j in range(1,30):
comparison = random.randint(1, 100)
comparison = secrets.SystemRandom().randint(1, 100)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace random.{func} with more secure secrets library functions.

if comparison <= probability:
heads += 1
heads_dist = numpy.insert(heads_dist, 0, heads)
Expand All @@ -52,7 +52,7 @@ def coinToss():


#seed rng
random.seed()
secrets.SystemRandom().seed()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace random.{func} with more secure secrets library functions.

#configure window
window = Tk()
window.title("Coin toss guessing game")
Expand Down