Results 1 to 6 of 6
  1. #1
    rcastillo106 is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Default

    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

  3. #3
    rcastillo106 is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    Well, I wrote this program:
    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");
        }
      }
    }
    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?
    Last edited by Eranga; 04-01-2010 at 04:53 AM. Reason: added code tags

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    rcastillo106 is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    Sorry, kind of new to this. Thanks for the heads up

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Nested Loops for Java
    By soccer_kid_6 in forum New To Java
    Replies: 4
    Last Post: 02-21-2010, 06:27 AM
  2. nested for loops
    By Implode in forum New To Java
    Replies: 4
    Last Post: 09-01-2009, 09:47 AM
  3. Nested Loops
    By ks1615 in forum New To Java
    Replies: 4
    Last Post: 02-18-2009, 03:48 AM
  4. Help combining loops into 1 program.
    By kewlgeye in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 10:58 AM
  5. Nested loops?
    By gabriel in forum New To Java
    Replies: 4
    Last Post: 08-06-2007, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •