Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
rev/java-rev-2 (#21)
Browse files Browse the repository at this point in the history
* init

* chall

* solvepath

* solvepath fixes

* make nominally easier with a hint

---------

Co-authored-by: mud-ali <[email protected]>
  • Loading branch information
Jack-Crowley and mud-ali authored Aug 26, 2023
1 parent 4a2ea46 commit 8c533c1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
30 changes: 30 additions & 0 deletions java-rev-2/RevTwo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.Scanner;

public class RevTwo {
public static void main(String[] args) {
System.out.println("Enter the password: ");
Scanner scanner = new Scanner(System.in);

String line = scanner.nextLine();

if (checkPassword(line)) {
System.out.println("That's the right password!");
} else {
System.out.println("That's the incorrect password!");
}

scanner.close();
}

public static boolean checkPassword(String passwordGuess) {
int[] nums = {7267, 6113, 11757, 7152, 7675, 6345, 9823, 11463, 8821, 12339, 8019, 6739, 5983, 11476, 10344, 11057, 11603, 5087, 8791, 11956, 12115, 11982, 4820, 10719, 8787, 6835, 9059, 6901, 11090, 5605, 7677};

for (int i = 0; i < passwordGuess.length(); i++) {
if ((int) passwordGuess.charAt(i) != nums[i] % 128) {
return false;
}
}

return true;
}
}
16 changes: 16 additions & 0 deletions java-rev-2/chall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Java Rev 2
categories:
- rev
value: 100
flag: camp{I_Gu3SS_Th1S_W4SNT_S3cuRe}
description: |-
After your last break-in, my friend informed me that he made it almost impossible to solve.
Can you still find the password?
hints:
- Do you know what ASCII is?
- What does the % do?
files:
- src: RevTwo.java
authors:
- Jack Crowley
visible: true
25 changes: 25 additions & 0 deletions java-rev-2/solve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Java Rev Two

This Java Rev challenge has an array with all of ascii values of the flag, however, they seem a little bit too high to fit into the normal 128 values.

This is where `modulus` or the `%`, which acts sort of like a `division` statement. However, instead of returning the evaluated results, it gives us the remainder. In this case, it takes `nums[i] % 128`, which means that it gets the number from the array and then takes the remainder of that number after being divided by 128.

For example, 6113 divided by 128 is 47, remainder 97. As such, 6113 mod 128 = 97

To solve this problem, you must first delete the `return False;` in the `checkPassword`, which enables the program to keep going even if the first character is wrong.

Then you must put a print statement inside the for loop which prints the correct character of the flag, such as:

```
System.out.print((char) (nums[i] % 128));
```

Note that `(char)` will display the corresponding character for the number.

Once you run the program, input a long and random input such as:

```
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

which will produce the correct flag in the terminal.

0 comments on commit 8c533c1

Please sign in to comment.