Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
V
Vault Hacking Race
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tammam.alsoleman
Vault Hacking Race
Commits
d05b2bbe
Commit
d05b2bbe
authored
Nov 04, 2025
by
tammam.alsoleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ADD_BinarySearchHacker
parent
897a00f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
BinarySearchHackerThread.java
src/BinarySearchHackerThread.java
+39
-0
Main.java
src/Main.java
+2
-0
Vault.java
src/Vault.java
+17
-0
No files found.
src/BinarySearchHackerThread.java
0 → 100644
View file @
d05b2bbe
public
class
BinarySearchHackerThread
extends
Thread
{
private
Vault
vault
;
private
int
attempts
;
public
BinarySearchHackerThread
(
Vault
vault
)
{
this
.
vault
=
vault
;
this
.
setName
(
"BinarySearchHacker"
);
this
.
setPriority
(
Thread
.
MAX_PRIORITY
);
this
.
attempts
=
0
;
}
@Override
public
void
run
()
{
System
.
out
.
println
(
this
.
getName
()
+
" started hacking with REAL binary search algorithm"
);
int
low
=
0
;
int
high
=
9999
;
while
(
low
<=
high
)
{
attempts
++;
int
mid
=
low
+
(
high
-
low
)
/
2
;
int
result
=
vault
.
comparePassword
(
mid
);
if
(
result
==
0
)
{
// Password is true
System
.
out
.
println
(
this
.
getName
()
+
" cracked the vault! Password: "
+
mid
);
System
.
out
.
println
(
"Binary search completed in "
+
attempts
+
" attempts"
);
System
.
exit
(
0
);
}
else
if
(
result
==
-
1
)
{
// less than password
low
=
mid
+
1
;
}
else
{
// bigger than Password
high
=
mid
-
1
;
}
}
}
}
\ No newline at end of file
src/Main.java
View file @
d05b2bbe
...
...
@@ -6,12 +6,14 @@ public class Main {
AscendingHackerThread
ascendingHacker
=
new
AscendingHackerThread
(
vault
);
DescendingHackerThread
descendingHacker
=
new
DescendingHackerThread
(
vault
);
BinarySearchHackerThread
binarySearchHacker
=
new
BinarySearchHackerThread
(
vault
);
PoliceThread
police
=
new
PoliceThread
();
System
.
out
.
println
(
"Starting all threads..."
);
ascendingHacker
.
start
();
descendingHacker
.
start
();
binarySearchHacker
.
start
();
police
.
start
();
System
.
out
.
println
(
"All threads are running !"
);
...
...
src/Vault.java
View file @
d05b2bbe
...
...
@@ -13,4 +13,21 @@ public class Vault {
}
return
guess
==
this
.
password
;
}
public
int
comparePassword
(
int
guess
)
{
try
{
Thread
.
sleep
(
5
);
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Exception during password comparison"
);
}
if
(
guess
==
this
.
password
)
{
return
0
;
}
else
if
(
guess
<
this
.
password
)
{
return
-
1
;
}
else
{
return
1
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment