Skip to content

Commit

Permalink
Updated Solution for Exercise 3
Browse files Browse the repository at this point in the history
- The solution had a bug in it that made it report the wrong success rate. Fixed and modified it to work again, making the exercise slightly harder.
- Adjusted the Exercise to include an easy version (the old one, which only works up to 5%) and a slightly harder one (the new 10%)
  • Loading branch information
Kayzaks committed Nov 26, 2019
1 parent 8a09375 commit 70f81c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
4 changes: 2 additions & 2 deletions 3_BruteForcing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

You are trying to Brute-Force a Image-based Security control. So far your attempt (see 'exercise.py') has proven to be unreliable. However, you have some vague idea of what an image that gives access should look like (see 'fake_id.png'), but it doesn't work either.

- Develop a brute-force strategy that has a success rate of about 10% or better
- Develop a brute-force strategy that has a success rate of about 5% or better (10% or better for a challenge)
- Do not modify 'model.h5'
- Do not simply draw a '4' in paint...

A solution can be found in 'solution_3_0.py'
A solution for 5% and 10% can be found in 'solution_3_0.py'
50 changes: 37 additions & 13 deletions 3_BruteForcing/solution_3_0.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'''
Solution to Exercise:
Solution to Exercise 3:
The idea is to add some noise to our best-guess fake-ID.
'''



import keras
import numpy as np
from skimage import io
Expand All @@ -16,10 +15,10 @@
runs = 1000
max_intensity = 10

print('Running pure Noise Test')
print('Running pure Random Test')
successes = 0
for i in range(runs):
# Creating a pure Noise Image
# Creating a pure Random Image
processedImage = np.random.random([1, 28, 28, 1])

# Run the Model and check what Digit was shown
Expand All @@ -29,10 +28,7 @@
if shownDigit == 4:
successes = successes + 1

print('Pure Noise had a ' + str(successes) + ' / ' + str(runs) + ' success rate')


print('Running Best Guess + Noise Test')
print('Pure Random had a ' + str(successes) + ' / ' + str(runs) + ' success rate')

# Best-Guess Fake ID
image = io.imread('./fake_id.png')
Expand All @@ -41,13 +37,41 @@
for xx in range(28):
originalImage[0][xx][yy][0] = float(image[xx][yy]) / 255

max_intensity = 10

for intensity in range(max_intensity):
print('Running Best Guess + Random Test')

min_intensity = 40 # / 100
max_intensity = 50 # / 100

for intensity in range(min_intensity, max_intensity):
successes = 0
for i in range(runs):
# Adding some Random noise to the image
noise = np.random.random([1, 28, 28, 1]) * float(intensity) * 0.01

processedImage = originalImage + noise

# Run the Model and check what Digit was shown
shownDigit = np.argmax(model.predict(processedImage))

# Only Digit 4 grants access!
if shownDigit == 4:
successes = successes + 1

print('Rand-Intensity ' + str(intensity) + ' had a ' + str(successes) + ' / ' + str(runs) + ' success rate')



print('Running Best Guess + Normal Distributed Noise Test')

min_intensity = 25 # / 100
max_intensity = 35 # / 100

for mu in range(min_intensity, max_intensity):
successes = 0
for i in range(runs):
# Adding some Noise to the image
noise = np.random.random([1, 28, 28, 1]) * float(intensity) * 0.1
# Adding some Normal distributed Noise to the image
noise = np.random.normal(float(mu) * 0.01, 0.05, [1, 28, 28, 1])

processedImage = originalImage + noise

Expand All @@ -58,4 +82,4 @@
if shownDigit == 4:
successes = successes + 1

print('Intensity ' + str(intensity) + ' had a ' + str(successes) + ' / ' + str(runs) + ' success rate')
print('Mu-intensity ' + str(mu) + ' had a ' + str(successes) + ' / ' + str(runs) + ' success rate')

0 comments on commit 70f81c5

Please sign in to comment.