-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBruteForceAttack.java
More file actions
37 lines (26 loc) · 1.09 KB
/
BruteForceAttack.java
File metadata and controls
37 lines (26 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class BruteForceAttack {
public static void bruteForceAttack(String encryptedText) {
StringBuilder result = new StringBuilder();
for (int s = 1; s < 26; s++) {
result.setLength(0);
for (int i = 0; i < encryptedText.length(); i++) {
char ch = encryptedText.charAt(i);
if (Character.isUpperCase(ch)) {
ch = (char) ((ch - 65 - s + 26) % 26 + 65);
} else if (Character.isLowerCase(ch)) {
ch = (char) ((ch - 97 - s + 26) % 26 + 97);
}
result.append(ch);
}
System.out.println("Shift: " + s + " -> " + result.toString());
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter an Encrypted text: ");
String encryptedText = sc.nextLine();
bruteForceAttack(encryptedText);
sc.close();
}
}