Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ATM.zip Contains the ATM classes and a simple implementation for a Card class. E

ID: 3576730 • Letter: A

Question

ATM.zip

Contains the ATM classes and a simple implementation for a Card class. Every card has a swipe method that takes in an ATM object that the card can use to validate is a real ATM. The ATM has a method applyDecryption() that the card must call to determine if the ATM has the proper credentials. The card must pass an encrypted code to applyDecryption() which will return a decrypted code. The card can then use this code to make sure the ATM has the appropriate private keys. If it does then the swipe method returns a Data object for ATM with info. (Look into Card.java for how this is done).

To see it in action, do the following in the ATM unzipped folder

This will show you an ATM UI. The Card.java contains the hardcoded pin.

ATM2 is the same except it does NOT pass an ATM object to the Card class so you have find the ATM class.

Problem

1. Modify the ATM class to allow the user to withdraw as much cash as there is in the machine. you do not have access to the source so you will have to resort to reflection. You can try this with the ATM.zip classes first since it already passes an ATM object to you.

2. Repeat Q1 but for ATM2 this time where an object is not passed to the Card. How do you get the ATM object? (This has to be the running object so simply doing an ATM a = new ATM() won't work. Do you understand why?).

3. There is a secret message in the ATM2 class. Find and decode it.

I am almost done with the three problems however there is minor issues.

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import java.awt.Frame;

public class Card
{
   private static String name = "Johnny Cash"; // Card holdersname
   private static int accountNumber = 978945; // Account number
   private static int pinNumber = 1234; //Pin Number
   private static int cardNumber = 123456789; // Card holders numbe
   private static int messageKey = 832923932; // Secret Message Key Encrypted
   private static int messageResult = 13439; // Secret Message Key Decrypted
   private static int index;

   /**
   * Part 2 of the Extra Credit Assignment (no ATM object is passed into the swipe method).
   * Bypasses the swipe method through manipulation of the frames. Also allows the user to take
   * all of the money out of the bank by manipulating his or her balance.
   */
   public static ATM.Data swipe()
   {
       try {
           ATM anATM = getATM(); //Gets the running object of the ATM.
           String dir = System.getProperty("user.dir");
           lookIntoFields(anATM);
           lookIntoMethods(anATM);
           int result = anATM.applyDecryption(messageKey);
           if (result == messageResult) {
               return new ATM.Data(cardNumber, accountNumber, name, pinNumber);
           }
       }
       catch(Exception e) { e.printStackTrace(); }
       return null;
   }
   /**
   * Part 1 of the Extra Credit Assignment (an ATM object is passed into the swipe method).
   * Allows the user to take all of the money out of the bank by manipulating his or her balance.
   */
   public static ATM.Data swipe(ATM anATM) {
       try
       {
           String dir = System.getProperty("user.dir");
           // lookIntoFields(anATM);
           // lookIntoMethods(anATM);
           int result = anATM.applyDecryption(messageKey);
           if (result == messageResult)
           {
               return new ATM.Data(cardNumber, accountNumber, name, pinNumber);
           }
       }
       catch (Exception e) { e.printStackTrace(); }
       return null;
   }
   private static Set<Class> setOfClasses;
   //Taken from previous HW assignment.
   public static void loadPackage(String path) throws Exception {
       setOfClasses = new HashSet<>();
       File[] packageContents = new File(path).listFiles();
       if (packageContents != null) //If there are files in the package
       {
           for (File file : packageContents) //For each file in the given package
           {
               String fileName = file.getName();
               if (fileName.contains(".class")) {
                   String fixedName = file.getName().substring(0, file.getName().length() - 6); //dropping extension.
                   Class c = Class.forName(fixedName);
                   setOfClasses.add(c);
               }
           }
       }
   }

   /**
   * Decrypts the secret message in ATM2.
   * @param the encoded secretMessage
   * @return the decoded secret message
   */
   public static String decryptCode(String secretMessage)
   {
       //taken from stack overflow
       String decodedMessage = "";
       for (int i = 0; i < secretMessage.length(); i++) {
           int x = secretMessage.charAt(i);
           //System.out.println("Decrpyting... " + x);
           if ((x >= 'a' && x <= 'm') || (x >= 'A' && x <= 'M')) {
               char c = ((char) (x += 13));
               decodedMessage += c;
           } else if ((x >= 'n' && x <= 'z') || (x >= 'N' && x <= 'Z')){
               char c = ((char) (x -= 13));
               decodedMessage += c;
           }
           else {
               decodedMessage += " ";
           }
       }
       return decodedMessage;
   }
   /**
   * "Hacks" the ATM so the user can withdraw all of the money in the machine.
   * @param anATM
   * @throws Exception
   */
   private static void hack(ATM anATM) throws Exception {
       Field moneyField = null;
       Field userBalanceField = null;
       Field message = null;
       for (Class c : setOfClasses) {
           Field[] declaredFields = c.getDeclaredFields();
           for (Field f : declaredFields) {
               f.setAccessible(true);
               if("SECRET_MESSAGE".equals(f.getName()))
               {
                   message = f;
                   System.out.println(decryptCode((String) f.get(name)));
               }
               if ("userBalance".equals(f.getName())) {
                   userBalanceField = f;
               }
               else if ("moneyInMachine".equals(f.getName())) {
                   moneyField = f;
               }
           }
       }
       //userBalanceField.setInt(anATM, Integer.MAX_VALUE);
       userBalanceField.setInt(anATM, moneyField.getInt(anATM));
   }

   private static ATM getATM()
   {
       return (ATM) Frame.getFrames()[0];
   }
}

Explanation / Answer

There is no zip attached.

Can you please attach the ATM.zip file

There is no zip attached.

Can you please attach the ATM.zip file

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote