Results 1 to 6 of 6
- 04-01-2010, 03:08 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Writing a program to crack a PIN number using nested for-loops
Hey I need help forming this program in my intro java programming class. Here;s what I have to do:
Write a program called CrackPIN (use nested for-loops) that guesses the PIN in the file.
I already created a .txt file in notepad with the pin. I actually even formed the .txt file through a program because that was the previous task before this one. I can't seem to figure this one out. Any help would be grateful. Thanks in advance.
- 04-01-2010, 03:34 AM #2
where have you got to. what exactly do you need help with. a Brute force algorithm??
see these links...
How To Ask Questions The Smart Way
Java Forums - BB Code List
Starting Writing a Program
EDIT:
sorry i'm not being rude,, just trying to help you to get help
kind regards
Sonny:p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts
- 04-01-2010, 03:44 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Well, I wrote this program:
Now I have to read from my pin.txt file and form a code to crack the pin I created. The pin was just 0000. I'm not sure how to go about doing it because if I make a for loop starting from 0-10000, I still wont get it because the pin has 4 zeros. Is this more information?Java Code:import java.lang.*; import java.util.*; import java.io.*; import javax.swing.*; public class FileLab3pt1 { public static void main (String[] args) { String pin = JOptionPane.showInputDialog("Please create a 4-digit PIN number"); String confirm = JOptionPane.showInputDialog("Please re-enter your 4-digit PIN number."); FileOutputStream outPin; PrintStream writePin; try { outPin = new FileOutputStream("C:\\Temp\\pin.txt"); writePin = new PrintStream(outPin); if (pin.equalsIgnoreCase(confirm)) { writePin.println(pin); System.out.println("The pin matches"); System.out.println ("Pin has been written and saved successfully."); } else{ System.out.println("The pin does not match, please run program again to store pin."); System.exit(0); } writePin.close(); } catch (Exception e){ System.err.println ("There has been an error in writing the file, please run program again"); } } }Last edited by Eranga; 04-01-2010 at 03:53 AM. Reason: added code tags
- 04-01-2010, 03:54 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Please use code tags also, next time you are posting the code segments here.
- 04-01-2010, 03:56 AM #5
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Sorry, kind of new to this. Thanks for the heads up
- 04-01-2010, 03:57 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think it's better if you can read more about I/O streams in Java, it's really helpful to you. Seems to me you stuck on with how to read the file. Isn't it?
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
Similar Threads
-
Nested Loops for Java
By soccer_kid_6 in forum New To JavaReplies: 4Last Post: 02-21-2010, 05:27 AM -
nested for loops
By Implode in forum New To JavaReplies: 4Last Post: 09-01-2009, 08:47 AM -
Nested Loops
By ks1615 in forum New To JavaReplies: 4Last Post: 02-18-2009, 02:48 AM -
Help combining loops into 1 program.
By kewlgeye in forum New To JavaReplies: 5Last Post: 04-22-2008, 09:58 AM -
Nested loops?
By gabriel in forum New To JavaReplies: 4Last Post: 08-06-2007, 04:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks