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
b79bcdf5
Commit
b79bcdf5
authored
Nov 04, 2025
by
tammam.alsoleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ADD_NumberOfAttempts
parent
d05b2bbe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
11 deletions
+36
-11
AscendingHackerThread.java
src/AscendingHackerThread.java
+9
-1
BinarySearchHackerThread.java
src/BinarySearchHackerThread.java
+5
-1
DescendingHackerThread.java
src/DescendingHackerThread.java
+8
-1
Main.java
src/Main.java
+1
-1
PoliceThread.java
src/PoliceThread.java
+13
-7
No files found.
src/AscendingHackerThread.java
View file @
b79bcdf5
public
class
AscendingHackerThread
extends
Thread
{
private
Vault
vault
;
private
int
attempts
;
public
AscendingHackerThread
(
Vault
vault
)
{
this
.
vault
=
vault
;
// Store the vault reference
this
.
setName
(
"AscendingHacker"
);
// Give this thread a clear name
this
.
setPriority
(
Thread
.
MAX_PRIORITY
);
// Give high priority
this
.
attempts
=
0
;
}
@Override
...
...
@@ -14,14 +16,20 @@ public class AscendingHackerThread extends Thread {
// Try every number from 0 to 9999
for
(
int
guess
=
0
;
guess
<
10000
;
guess
++)
{
// Check if this guess is correct
attempts
++;
if
(
vault
.
isCorrectPassword
(
guess
))
{
System
.
out
.
println
(
this
.
getName
()
+
" cracked the vault! Password: "
+
guess
);
System
.
out
.
println
(
"Total attempts: "
+
attempts
);
System
.
exit
(
0
);
// End the entire program
}
}
// If we get here, we didn't find the password
System
.
out
.
println
(
this
.
getName
()
+
" finished but didn't find the password!"
);
System
.
out
.
println
(
this
.
getName
()
+
" finished but didn't find the password! Total attempts: "
+
attempts
);
}
public
int
getAttempts
()
{
return
attempts
;
}
}
\ No newline at end of file
src/BinarySearchHackerThread.java
View file @
b79bcdf5
...
...
@@ -25,7 +25,7 @@ public class BinarySearchHackerThread extends Thread {
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
.
out
.
println
(
"
Total attempts: "
+
attempts
);
System
.
exit
(
0
);
}
else
if
(
result
==
-
1
)
{
// less than password
...
...
@@ -35,5 +35,9 @@ public class BinarySearchHackerThread extends Thread {
high
=
mid
-
1
;
}
}
System
.
out
.
println
(
this
.
getName
()
+
" finished! Total attempts: "
+
attempts
);
}
public
int
getAttempts
()
{
return
attempts
;
}
}
\ No newline at end of file
src/DescendingHackerThread.java
View file @
b79bcdf5
public
class
DescendingHackerThread
extends
Thread
{
private
Vault
vault
;
private
int
attempts
;
public
DescendingHackerThread
(
Vault
vault
)
{
this
.
vault
=
vault
;
this
.
setName
(
"DescendingHacker"
);
this
.
setPriority
(
Thread
.
MAX_PRIORITY
);
this
.
attempts
=
0
;
}
@Override
...
...
@@ -13,11 +15,16 @@ public class DescendingHackerThread extends Thread {
// Try every number from 9999 down to 0
for
(
int
guess
=
9999
;
guess
>=
0
;
guess
--)
{
attempts
++;
if
(
vault
.
isCorrectPassword
(
guess
))
{
System
.
out
.
println
(
this
.
getName
()
+
" cracked the vault! Password: "
+
guess
);
System
.
out
.
println
(
"Total attempts: "
+
attempts
);
System
.
exit
(
0
);
}
}
System
.
out
.
println
(
this
.
getName
()
+
" finished but didn't find the password!"
);
System
.
out
.
println
(
this
.
getName
()
+
" finished but didn't find the password! Total attempts: "
+
attempts
);
}
public
int
getAttempts
()
{
return
attempts
;
}
}
\ No newline at end of file
src/Main.java
View file @
b79bcdf5
...
...
@@ -7,7 +7,7 @@ public class Main {
AscendingHackerThread
ascendingHacker
=
new
AscendingHackerThread
(
vault
);
DescendingHackerThread
descendingHacker
=
new
DescendingHackerThread
(
vault
);
BinarySearchHackerThread
binarySearchHacker
=
new
BinarySearchHackerThread
(
vault
);
PoliceThread
police
=
new
PoliceThread
();
PoliceThread
police
=
new
PoliceThread
(
ascendingHacker
,
descendingHacker
,
binarySearchHacker
);
System
.
out
.
println
(
"Starting all threads..."
);
...
...
src/PoliceThread.java
View file @
b79bcdf5
public
class
PoliceThread
extends
Thread
{
private
AscendingHackerThread
ascendingHacker
;
private
DescendingHackerThread
descendingHacker
;
private
BinarySearchHackerThread
binarySearchHacker
;
public
PoliceThread
()
{
public
PoliceThread
(
AscendingHackerThread
asc
,
DescendingHackerThread
desc
,
BinarySearchHackerThread
bin
)
{
this
.
setName
(
"Police"
);
this
.
ascendingHacker
=
asc
;
this
.
descendingHacker
=
desc
;
this
.
binarySearchHacker
=
bin
;
}
@Override
public
void
run
()
{
System
.
out
.
println
(
"Police are on the way! 10 seconds remaining..."
);
// Countdown from 10 to 1
for
(
int
i
=
10
;
i
>
0
;
i
--)
{
try
{
// Wait for 1 second (1000 milliseconds)
Thread
.
sleep
(
1000
);
System
.
out
.
println
(
i
+
" seconds remaining..."
);
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Police thread was interrupted!"
);
e
.
printStackTrace
();
}
}
// If we reach here, time is up and police arrived
System
.
out
.
println
(
"Game over for you hackers! Police arrived!"
);
System
.
exit
(
0
);
// End the entire program
}
System
.
out
.
println
(
"Ascending Hacker attempts: "
+
ascendingHacker
.
getAttempts
());
System
.
out
.
println
(
"Descending Hacker attempts: "
+
descendingHacker
.
getAttempts
());
System
.
out
.
println
(
"Binary Search Hacker attempts: "
+
binarySearchHacker
.
getAttempts
());
System
.
exit
(
0
);
}
}
\ 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