Skip to content

Commit 9d36ba7

Browse files
Merge branch 'master' into docs/remove-readme-ko
2 parents bbd372c + 6fdf2db commit 9d36ba7

File tree

113 files changed

+4104
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4104
-241
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ In order to reduce the number of notifications sent to the maintainers, please:
1313
- [ ] All filenames are in PascalCase.
1414
- [ ] All functions and variable names follow Java naming conventions.
1515
- [ ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
16-
- [ ] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`
16+
- [ ] All new algorithms include a corresponding test class that validates their functionality.
17+
- [ ] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

.github/workflows/infer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Cache infer build
3535
id: cache-infer
36-
uses: actions/cache@v4
36+
uses: actions/cache@v5
3737
with:
3838
path: infer
3939
key: ${{ runner.os }}-infer-${{ env.year_week }}

.github/workflows/update-directorymd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
git diff --cached --quiet || git commit -m "Update DIRECTORY.md"
3434
3535
- name: Create Pull Request
36-
uses: peter-evans/create-pull-request@v7
36+
uses: peter-evans/create-pull-request@v8
3737
with:
3838
token: ${{ secrets.REPO_SCOPED_TOKEN }}
3939
branch: update-directory

.gitpod.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gitpod/workspace-java-21:2025-10-06-13-14-25
1+
FROM gitpod/workspace-java-21:2025-11-14-10-05-32
22

33
ENV LLVM_SCRIPT="tmp_llvm.sh"
44

DIRECTORY.md

Lines changed: 36 additions & 2 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.junit</groupId>
2222
<artifactId>junit-bom</artifactId>
23-
<version>6.0.1</version>
23+
<version>6.0.2</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>org.mockito</groupId>
4444
<artifactId>mockito-core</artifactId>
45-
<version>5.20.0</version>
45+
<version>5.21.0</version>
4646
<scope>test</scope>
4747
</dependency>
4848
<dependency>
@@ -112,22 +112,22 @@
112112
<dependency>
113113
<groupId>com.puppycrawl.tools</groupId>
114114
<artifactId>checkstyle</artifactId>
115-
<version>12.1.2</version>
115+
<version>13.0.0</version>
116116
</dependency>
117117
</dependencies>
118118
</plugin>
119119
<plugin>
120120
<groupId>com.github.spotbugs</groupId>
121121
<artifactId>spotbugs-maven-plugin</artifactId>
122-
<version>4.9.8.1</version>
122+
<version>4.9.8.2</version>
123123
<configuration>
124124
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
125125
<includeTests>true</includeTests>
126126
<plugins>
127127
<plugin>
128128
<groupId>com.mebigfatguy.fb-contrib</groupId>
129129
<artifactId>fb-contrib</artifactId>
130-
<version>7.7.0</version>
130+
<version>7.7.4</version>
131131
</plugin>
132132
<plugin>
133133
<groupId>com.h3xstream.findsecbugs</groupId>

spotbugs-exclude.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@
207207
<Match>
208208
<Bug pattern="FII_USE_ARRAYS_STREAM" />
209209
</Match>
210+
<Match>
211+
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_USE_ASSERT_EQUALS" />
212+
</Match>
213+
<Match>
214+
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE" />
215+
</Match>
210216
<!-- find-sec-bugs -->
211217
<Match>
212218
<Bug pattern="PREDICTABLE_RANDOM" />

src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,36 @@
44
import java.util.List;
55

66
/**
7-
* Program description - To find all possible paths from source to destination
8-
* <a href="https://en.wikipedia.org/wiki/Shortest_path_problem">Wikipedia</a>
7+
* Finds all possible simple paths from a given source vertex to a destination vertex
8+
* in a directed graph using backtracking.
99
*
10-
* @author <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
10+
* <p>This algorithm performs a Depth First Search (DFS) traversal while keeping track
11+
* of visited vertices to avoid cycles. Whenever the destination vertex is reached,
12+
* the current path is stored as one valid path.</p>
13+
*
14+
* <p><b>Key Characteristics:</b></p>
15+
* <ul>
16+
* <li>Works on directed graphs</li>
17+
* <li>Does not allow revisiting vertices in the same path</li>
18+
* <li>Stores all possible paths from source to destination</li>
19+
* </ul>
20+
*
21+
* <p><b>Time Complexity:</b></p>
22+
* <ul>
23+
* <li>Worst Case: O(V!) — when the graph is fully connected</li>
24+
* </ul>
25+
*
26+
* <p><b>Space Complexity:</b></p>
27+
* <ul>
28+
* <li>O(V) for recursion stack and visited array</li>
29+
* <li>Additional space for storing all valid paths</li>
30+
* </ul>
31+
*
32+
* <p>This implementation is intended for educational purposes.</p>
33+
*
34+
* @see <a href="https://en.wikipedia.org/wiki/Depth-first_search">Depth First Search</a>
1135
*/
36+
1237
@SuppressWarnings({"rawtypes", "unchecked"})
1338
public class AllPathsFromSourceToTarget {
1439

src/main/java/com/thealgorithms/backtracking/Combination.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import java.util.TreeSet;
88

99
/**
10-
* Finds all permutations of given array
11-
* @author Alan Piao (<a href="https://github.com/cpiao3">git-Alan Piao</a>)
10+
* Finds all combinations of a given array using backtracking algorithm * @author Alan Piao (<a href="https://github.com/cpiao3">git-Alan Piao</a>)
1211
*/
1312
public final class Combination {
1413
private Combination() {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.thealgorithms.ciphers;
2+
3+
import java.security.SecureRandom;
4+
import java.util.Objects;
5+
6+
/**
7+
* One-Time Pad (OTP) cipher implementation.
8+
*
9+
* <p>The One-Time Pad is information-theoretically secure if:
10+
* <ul>
11+
* <li>The key is truly random.</li>
12+
* <li>The key length is at least as long as the plaintext.</li>
13+
* <li>The key is used only once and kept secret.</li>
14+
* </ul>
15+
*
16+
* <p>This implementation is for <b>educational purposes only</b> and should not be
17+
* used in production systems.
18+
*/
19+
public final class OneTimePadCipher {
20+
21+
private static final SecureRandom RANDOM = new SecureRandom();
22+
23+
private OneTimePadCipher() {
24+
// utility class
25+
}
26+
27+
/**
28+
* Generates a random key of the given length in bytes.
29+
*
30+
* @param length the length of the key in bytes, must be non-negative
31+
* @return a new random key
32+
* @throws IllegalArgumentException if length is negative
33+
*/
34+
public static byte[] generateKey(int length) {
35+
if (length < 0) {
36+
throw new IllegalArgumentException("length must be non-negative");
37+
}
38+
byte[] key = new byte[length];
39+
RANDOM.nextBytes(key);
40+
return key;
41+
}
42+
43+
/**
44+
* Encrypts the given plaintext bytes using the provided key.
45+
* <p>The key length must be exactly the same as the plaintext length.
46+
*
47+
* @param plaintext the plaintext bytes, must not be {@code null}
48+
* @param key the one-time pad key bytes, must not be {@code null}
49+
* @return the ciphertext bytes
50+
* @throws IllegalArgumentException if the key length does not match plaintext length
51+
* @throws NullPointerException if plaintext or key is {@code null}
52+
*/
53+
public static byte[] encrypt(byte[] plaintext, byte[] key) {
54+
validateInputs(plaintext, key);
55+
return xor(plaintext, key);
56+
}
57+
58+
/**
59+
* Decrypts the given ciphertext bytes using the provided key.
60+
* <p>For a One-Time Pad, decryption is identical to encryption:
61+
* {@code plaintext = ciphertext XOR key}.
62+
*
63+
* @param ciphertext the ciphertext bytes, must not be {@code null}
64+
* @param key the one-time pad key bytes, must not be {@code null}
65+
* @return the decrypted plaintext bytes
66+
* @throws IllegalArgumentException if the key length does not match ciphertext length
67+
* @throws NullPointerException if ciphertext or key is {@code null}
68+
*/
69+
public static byte[] decrypt(byte[] ciphertext, byte[] key) {
70+
validateInputs(ciphertext, key);
71+
return xor(ciphertext, key);
72+
}
73+
74+
private static void validateInputs(byte[] input, byte[] key) {
75+
Objects.requireNonNull(input, "input must not be null");
76+
Objects.requireNonNull(key, "key must not be null");
77+
if (input.length != key.length) {
78+
throw new IllegalArgumentException("Key length must match input length");
79+
}
80+
}
81+
82+
private static byte[] xor(byte[] data, byte[] key) {
83+
byte[] result = new byte[data.length];
84+
for (int i = 0; i < data.length; i++) {
85+
result[i] = (byte) (data[i] ^ key[i]);
86+
}
87+
return result;
88+
}
89+
}

0 commit comments

Comments
 (0)