Skip to content

Commit 78191c7

Browse files
committed
Update V. 1.0
1 parent 371a6d5 commit 78191c7

4 files changed

Lines changed: 33 additions & 33 deletions

File tree

src/api/zerodeveloping/KeyGenerator.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,44 @@ public void setPattern(KeyPattern pattern) {
99
this.pattern = pattern;
1010
}
1111

12-
public void generate() {
12+
public String generate() {
1313
String[] sections = pattern.getKey_pattern().split("-");
1414

1515
int security_numbers = (int) (Math.ceil(sections.length / 2.0));
1616
int maxAscii = 0;
1717
int ascii_multiplier = 0;
18+
1819
for (String section : sections) {
1920
maxAscii += section.length();
2021
for(int i = 0; i < section.length(); i++){
2122
int ascii_char = (int) section.charAt(i);
22-
if(ascii_char > ascii_multiplier){
23-
ascii_multiplier = ascii_char;
24-
}
23+
if(ascii_char > ascii_multiplier) ascii_multiplier = ascii_char;
2524
}
2625
}
2726
maxAscii *= ascii_multiplier;
28-
try{
29-
if(pattern.getAscii_count() > maxAscii) throw new AsciiException(maxAscii, pattern.getAscii_count());
30-
31-
}catch (AsciiException e){
32-
e.printStackTrace();
33-
}
27+
try{if(pattern.getAscii_count() > maxAscii) throw new AsciiException(maxAscii, pattern.getAscii_count());}catch (AsciiException e){e.printStackTrace();}
3428

3529
String key = "";
3630
while(true) {
3731
int char_counter = 0;
3832
int counter = 0;
3933
for (String section : sections) {
4034
counter++;
41-
for(int i = 0; i < section.length(); i++) {
42-
key += pattern.getAlphabet_pattern().charAt((int) Math.round(Math.random() * (pattern.getAlphabet_pattern().length() - 1)));
43-
}
44-
if(counter != sections.length)
45-
key += "-";
35+
for(int i = 0; i < section.length(); i++) key += pattern.getAlphabet_pattern().charAt((int) Math.round(Math.random() * (pattern.getAlphabet_pattern().length() - 1)));
36+
37+
if(counter != sections.length) key += "-";
4638
}
4739
counter = 0;
4840

49-
for(int i = 0; i < key.length(); i++) {
50-
if(key.charAt(i) == pattern.getControl_number()) {
51-
char_counter++;
52-
}
53-
}
41+
for(int i = 0; i < key.length(); i++) if(key.charAt(i) == pattern.getControl_number()) char_counter++;
5442

5543
if(security_numbers <= char_counter) {
5644
int ascii_count = 0;
5745
for(int i = 0; i < key.length(); i++) {
58-
if(key.charAt(i) != '-') {
59-
ascii_count += (int) key.charAt(i);
60-
}
46+
if(key.charAt(i) != '-') ascii_count += (int) key.charAt(i);
6147
}
6248
if(ascii_count == pattern.getAscii_count()) {
63-
System.out.println(key);
64-
break;
49+
return key;
6550
}
6651
}
6752
key = "";

src/api/zerodeveloping/KeyPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public KeyPattern(String key_pattern, char control_number, int ascii_count, Stri
1818
}
1919

2020
public static KeyPattern getDefault(){
21-
return new KeyPattern("aaaa-aaaa-aaaa-aaaa-1111",'7', 50000, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYL0123456789");
21+
return new KeyPattern("aaaa-aaaa-aaaa-aaaa-aaaa",'7', 1648, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYL0123456789");
2222
}
2323

2424
public String getKey_pattern() {

src/examples/CreateKey.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package examples;
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 CreateKey {
10+
//A simple test method to create a key
11+
public static void main(String[] args) {
12+
KeyGenerator keyGenerator = new KeyGenerator();
13+
keyGenerator.setPattern(KeyPattern.getDefault());
14+
15+
String key = keyGenerator.generate();
16+
System.out.println(key);
17+
}
18+
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
package api.zerodeveloping.main;
1+
package examples;
22

3-
import api.zerodeveloping.KeyGenerator;
43
import api.zerodeveloping.KeyPattern;
54
import api.zerodeveloping.KeyScanner;
65

76
import java.util.Scanner;
87

9-
public class Main {
8+
public class ScanKey {
9+
//A simple test method to scan a key
1010
public static void main(String[] args) {
11-
KeyGenerator keyGenerator = new KeyGenerator();
12-
keyGenerator.setPattern(KeyPattern.getDefault());
13-
keyGenerator.generate();
14-
1511
KeyScanner keyScanner = new KeyScanner();
1612
keyScanner.setPattern(KeyPattern.getDefault());
1713
Scanner scanner = new Scanner(System.in);
14+
1815
if(keyScanner.isValid(scanner.nextLine())){
1916
System.out.println("Key Valid");
2017
}else{

0 commit comments

Comments
 (0)