Skip to content

Commit 371a6d5

Browse files
committed
Renamed File | Updated Functions
1 parent a50575c commit 371a6d5

7 files changed

Lines changed: 145 additions & 61 deletions

File tree

src/api/iampekka058/generate/KeyGeneratorPattern.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/api/iampekka058/main/Main.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/api/iampekka058/generate/KeyGenerator.java renamed to src/api/zerodeveloping/KeyGenerator.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package api.iampekka058.generate;
1+
package api.zerodeveloping;
2+
3+
import api.zerodeveloping.exception.AsciiException;
24

35
public class KeyGenerator {
4-
KeyGeneratorPattern pattern;
6+
KeyPattern pattern;
57

6-
public void setPattern(KeyGeneratorPattern pattern) {
8+
public void setPattern(KeyPattern pattern) {
79
this.pattern = pattern;
810
}
911

@@ -12,13 +14,23 @@ public void generate() {
1214

1315
int security_numbers = (int) (Math.ceil(sections.length / 2.0));
1416
int maxAscii = 0;
17+
int ascii_multiplier = 0;
1518
for (String section : sections) {
1619
maxAscii += section.length();
20+
for(int i = 0; i < section.length(); i++){
21+
int ascii_char = (int) section.charAt(i);
22+
if(ascii_char > ascii_multiplier){
23+
ascii_multiplier = ascii_char;
24+
}
25+
}
1726
}
18-
maxAscii *= 125;
19-
maxAscii *= 0.8;
27+
maxAscii *= ascii_multiplier;
28+
try{
29+
if(pattern.getAscii_count() > maxAscii) throw new AsciiException(maxAscii, pattern.getAscii_count());
2030

21-
System.out.println(maxAscii);
31+
}catch (AsciiException e){
32+
e.printStackTrace();
33+
}
2234

2335
String key = "";
2436
while(true) {
@@ -40,23 +52,18 @@ public void generate() {
4052
}
4153
}
4254

43-
if(security_numbers == char_counter) {
55+
if(security_numbers <= char_counter) {
4456
int ascii_count = 0;
4557
for(int i = 0; i < key.length(); i++) {
4658
if(key.charAt(i) != '-') {
4759
ascii_count += (int) key.charAt(i);
4860
}
4961
}
5062
if(ascii_count == pattern.getAscii_count()) {
51-
System.exit(0);
52-
} else {
53-
System.out.println(ascii_count);
63+
System.out.println(key);
64+
break;
5465
}
55-
} else {
56-
System.out.println(char_counter);
5766
}
58-
System.out.println(key);
59-
6067
key = "";
6168
}
6269
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package api.zerodeveloping;
2+
3+
public class KeyPattern {
4+
private String key_pattern;
5+
private char control_number;
6+
private int ascii_count;
7+
private String alphabet_pattern;
8+
private String alphabet_lower = "abcdefghijklmnopqrstuvwxyz";
9+
private String alphabet_higher = "ABCDEFGHIJKLMNOPQRSTUVWXYL";
10+
private String digits = "0123456789";
11+
private String punctuation = "§$%&/()=?";
12+
13+
public KeyPattern(String key_pattern, char control_number, int ascii_count, String alphabet_pattern){
14+
this.key_pattern = key_pattern;
15+
this.control_number = control_number;
16+
this.ascii_count = ascii_count;
17+
this.alphabet_pattern = alphabet_pattern;
18+
}
19+
20+
public static KeyPattern getDefault(){
21+
return new KeyPattern("aaaa-aaaa-aaaa-aaaa-1111",'7', 50000, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYL0123456789");
22+
}
23+
24+
public String getKey_pattern() {
25+
return key_pattern;
26+
}
27+
28+
public String getAlphabet_pattern() {
29+
return alphabet_pattern;
30+
}
31+
32+
public char getControl_number() {
33+
return control_number;
34+
}
35+
36+
public int getAscii_count() {
37+
return ascii_count;
38+
}
39+
40+
public String getAlphabet_higher() {
41+
return alphabet_higher;
42+
}
43+
44+
public String getAlphabet_lower() {
45+
return alphabet_lower;
46+
}
47+
48+
public String getDigits() {
49+
return digits;
50+
}
51+
52+
public String getPunctuation() {
53+
return punctuation;
54+
}
55+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package api.zerodeveloping;
2+
3+
public class KeyScanner {
4+
5+
KeyPattern pattern;
6+
7+
public void setPattern(KeyPattern pattern) {
8+
this.pattern = pattern;
9+
}
10+
11+
public boolean isValid(String key){
12+
String[] sections_pattern = pattern.getKey_pattern().split("-");
13+
String[] sections_key = key.split("-");
14+
15+
int char_counter = 0;
16+
int ascii_count = 0;
17+
int security_numbers = (int) (Math.ceil(sections_pattern.length / 2.0));
18+
19+
if(sections_pattern.length != sections_key.length) return false;
20+
for(int i = 0; i < sections_pattern.length; i++){
21+
if(sections_pattern[i].length() != sections_key[i].length()) return false;
22+
}
23+
for(int i = 0; i < key.length(); i++) {
24+
if(key.charAt(i) == pattern.getControl_number()) {
25+
char_counter++;
26+
}
27+
}
28+
if(char_counter < security_numbers) return false;
29+
for(int i = 0; i < key.length(); i++) {
30+
if(key.charAt(i) != '-') {
31+
ascii_count += (int) key.charAt(i);
32+
}
33+
}
34+
if(ascii_count==pattern.getAscii_count()) return true;
35+
36+
return false;
37+
}
38+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package api.zerodeveloping.exception;
2+
3+
public class AsciiException extends Exception {
4+
public AsciiException(int max_ascii_code, int current_ascii_code){
5+
super("Your selected ascii code is to high! Max:"+max_ascii_code+" | Current:"+current_ascii_code+" | Recommended around:"+max_ascii_code*0.7);
6+
}
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package api.zerodeveloping.main;
2+
3+
import api.zerodeveloping.KeyGenerator;
4+
import api.zerodeveloping.KeyPattern;
5+
import api.zerodeveloping.KeyScanner;
6+
7+
import java.util.Scanner;
8+
9+
public class Main {
10+
public static void main(String[] args) {
11+
KeyGenerator keyGenerator = new KeyGenerator();
12+
keyGenerator.setPattern(KeyPattern.getDefault());
13+
keyGenerator.generate();
14+
15+
KeyScanner keyScanner = new KeyScanner();
16+
keyScanner.setPattern(KeyPattern.getDefault());
17+
Scanner scanner = new Scanner(System.in);
18+
if(keyScanner.isValid(scanner.nextLine())){
19+
System.out.println("Key Valid");
20+
}else{
21+
System.out.println("Key Invalid");
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)