Hey I need some help with a java application i have been playing with.
I was trying to write a basic console app that breaks a password that is conatined within the program itself. SO basicly I have an app that starts checking if one string equals the password one letter at a time, it starts with one letters then move son to two until it finds the right combination of letters. I got that much done and it worked, until I tried to have it start over again with a user input password once it cracks the first one. I want it to ask you to try again, then if you enetr y, then it asks u to enter a up to 10 letter string, ste that as the new password and begin process over again. Heres my orignal code:
import java.io.*;
import StringReader;
class passworder {
static String charIncrement(String pass, int index) {
String temp = "";
for(int i = 0; i < pass.length(); i++) {
temp += (char) (i == index ? pass.charAt(i) + 1: pass.charAt(i));
}
return temp;
}
static String reset(String pass, int index) {
String temp = "";
for(int i = 0; i < pass.length(); i++) {
temp += (char) (i == index ? '0': pass.charAt(i));
}
return temp;
}
public static void main(String args[]) {
System.out.println("Attempting to dechipher password");
int flager = 0;
StringReader ob = new StringReader("dad");
String guess = "0";
int flag = 0;
label1 : {
label : {
for(int a = 47; a <= 121; a++) {
if(flager == 1) guess = reset(guess, guess.length() - 9);
for(int b = 47; b <= 121; b++) {
if(flager == 1) guess = reset(guess, guess.length() - 8);
for(int c = 47; c <= 121; c++) {
if(flager == 1) guess = reset(guess, guess.length() - 7);
for(int d = 47; d <= 121; d++) {
if(flager == 1) guess = reset(guess, guess.length() - 6);
for(int e = 47; e <= 121; e++) {
if(flager == 1) guess = reset(guess, guess.length() - 5);
for(int f = 47; f <= 121; f++) {
if(flager == 1) guess = reset(guess, guess.length() - 4);
for(int g = 47; g <= 121; g++) {
if(flager == 1) guess = reset(guess, guess.length() - 3);
for(int h = 47; h <= 121; h++) {
if(flager == 1) guess = reset(guess, guess.length() - 2);
for(int i = 47; i <= 121; i++) {
if(flager == 1) guess = reset(guess, guess.length() - 1);
for(int j = 47; j <= 121; j++) {
if(flag == 0) {
guess = "0";
System.out.println("Trying One Letter Passwords");
System.out.println(guess);
flag = 1;
}
if(ob.password(guess)) break label;
guess = charIncrement(guess, (guess.length() - 1));
}
flager = 1;
if(flag == 1) {
guess = "00";
System.out.println("Trying Two Letter Passwords");
System.out.println(guess);
flag = 2;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 2));
}
if(flag == 2) {
guess = "000";
System.out.println("Trying Three Letter Passwords");
System.out.println(guess);
flag = 3;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 3));
}
if(flag == 3) {
guess = "0000";
System.out.println("Trying Four Letter Passwords");
System.out.println(guess);
flag = 4;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 4));
}
if(flag == 4) {
guess = "00000";
System.out.println("Trying Five Letter Passwords");
System.out.println(guess);
flag = 5;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 5));
}
if(flag == 5) {
guess = "000000";
System.out.println("Trying Sicks Letter Passwords");
System.out.println(guess);
flag = 6;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 6));
}
if(flag == 6) {
guess = "0000000";
System.out.println("Trying Seven Letter Passwords");
System.out.println(guess);
flag = 7;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 7));
}
if(flag == 7) {
guess = "00000000";
System.out.println("Trying Eight Letter Passwords");
System.out.println(guess);
flag = 8;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 8));
}
if(flag == 8) {
guess = "000000000";
System.out.println("Trying Nine Letter Passwords");
System.out.println(guess);
flag = 9;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 9));
}
if(flag == 9) {
guess = "0000000000";
System.out.println("Trying Ten Letter Passwords");
System.out.println(guess);
flag = 10;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 10));
}
}
System.out.println("Password is: " + guess);
System.out.println("Try Again?");
BufferedReader rb = new BufferedReader(new InputStreamReader(System.in));
char c=0;
try {
c = (char) rb.read();
}catch(java.io.IOException e){}
if(c == 71){
flager = 0;
guess = "0";
flag = 0;
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String str="hi";
System.out.println("Enter new password");
try {
str = br.readLine();
}catch(java.io.IOException e){}
ob = new StringReader(str);
}break label1;
}
}
}
heres the stringreader class code:
import java.io.*;
class StringReader{
static private String key;
StringReader(String pass){
key = pass;
}
static boolean password(String string) {
boolean i;
i =string.equals(key);
if(i) {
System.out.println("Access Granted, Password correct");
return i;
}
else {
return i;
}
}
}
Thanks, please feel free to suggest anything, such as ways to do this better, optimizatiosn of my code, any critiques are appreciated
I was trying to write a basic console app that breaks a password that is conatined within the program itself. SO basicly I have an app that starts checking if one string equals the password one letter at a time, it starts with one letters then move son to two until it finds the right combination of letters. I got that much done and it worked, until I tried to have it start over again with a user input password once it cracks the first one. I want it to ask you to try again, then if you enetr y, then it asks u to enter a up to 10 letter string, ste that as the new password and begin process over again. Heres my orignal code:
import java.io.*;
import StringReader;
class passworder {
static String charIncrement(String pass, int index) {
String temp = "";
for(int i = 0; i < pass.length(); i++) {
temp += (char) (i == index ? pass.charAt(i) + 1: pass.charAt(i));
}
return temp;
}
static String reset(String pass, int index) {
String temp = "";
for(int i = 0; i < pass.length(); i++) {
temp += (char) (i == index ? '0': pass.charAt(i));
}
return temp;
}
public static void main(String args[]) {
System.out.println("Attempting to dechipher password");
int flager = 0;
StringReader ob = new StringReader("dad");
String guess = "0";
int flag = 0;
label1 : {
label : {
for(int a = 47; a <= 121; a++) {
if(flager == 1) guess = reset(guess, guess.length() - 9);
for(int b = 47; b <= 121; b++) {
if(flager == 1) guess = reset(guess, guess.length() - 8);
for(int c = 47; c <= 121; c++) {
if(flager == 1) guess = reset(guess, guess.length() - 7);
for(int d = 47; d <= 121; d++) {
if(flager == 1) guess = reset(guess, guess.length() - 6);
for(int e = 47; e <= 121; e++) {
if(flager == 1) guess = reset(guess, guess.length() - 5);
for(int f = 47; f <= 121; f++) {
if(flager == 1) guess = reset(guess, guess.length() - 4);
for(int g = 47; g <= 121; g++) {
if(flager == 1) guess = reset(guess, guess.length() - 3);
for(int h = 47; h <= 121; h++) {
if(flager == 1) guess = reset(guess, guess.length() - 2);
for(int i = 47; i <= 121; i++) {
if(flager == 1) guess = reset(guess, guess.length() - 1);
for(int j = 47; j <= 121; j++) {
if(flag == 0) {
guess = "0";
System.out.println("Trying One Letter Passwords");
System.out.println(guess);
flag = 1;
}
if(ob.password(guess)) break label;
guess = charIncrement(guess, (guess.length() - 1));
}
flager = 1;
if(flag == 1) {
guess = "00";
System.out.println("Trying Two Letter Passwords");
System.out.println(guess);
flag = 2;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 2));
}
if(flag == 2) {
guess = "000";
System.out.println("Trying Three Letter Passwords");
System.out.println(guess);
flag = 3;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 3));
}
if(flag == 3) {
guess = "0000";
System.out.println("Trying Four Letter Passwords");
System.out.println(guess);
flag = 4;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 4));
}
if(flag == 4) {
guess = "00000";
System.out.println("Trying Five Letter Passwords");
System.out.println(guess);
flag = 5;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 5));
}
if(flag == 5) {
guess = "000000";
System.out.println("Trying Sicks Letter Passwords");
System.out.println(guess);
flag = 6;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 6));
}
if(flag == 6) {
guess = "0000000";
System.out.println("Trying Seven Letter Passwords");
System.out.println(guess);
flag = 7;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 7));
}
if(flag == 7) {
guess = "00000000";
System.out.println("Trying Eight Letter Passwords");
System.out.println(guess);
flag = 8;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 8));
}
if(flag == 8) {
guess = "000000000";
System.out.println("Trying Nine Letter Passwords");
System.out.println(guess);
flag = 9;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 9));
}
if(flag == 9) {
guess = "0000000000";
System.out.println("Trying Ten Letter Passwords");
System.out.println(guess);
flag = 10;
if(ob.password(guess)) break label;
}
guess = charIncrement(guess, (guess.length() - 10));
}
}
System.out.println("Password is: " + guess);
System.out.println("Try Again?");
BufferedReader rb = new BufferedReader(new InputStreamReader(System.in));
char c=0;
try {
c = (char) rb.read();
}catch(java.io.IOException e){}
if(c == 71){
flager = 0;
guess = "0";
flag = 0;
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String str="hi";
System.out.println("Enter new password");
try {
str = br.readLine();
}catch(java.io.IOException e){}
ob = new StringReader(str);
}break label1;
}
}
}
heres the stringreader class code:
import java.io.*;
class StringReader{
static private String key;
StringReader(String pass){
key = pass;
}
static boolean password(String string) {
boolean i;
i =string.equals(key);
if(i) {
System.out.println("Access Granted, Password correct");
return i;
}
else {
return i;
}
}
}
Thanks, please feel free to suggest anything, such as ways to do this better, optimizatiosn of my code, any critiques are appreciated