Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given Java code below, please use it as the base. mport java.util.Scanner; public class LA2a { /** * Number of digits in a valid value

Given Java code below, please use it as the base.

image text in transcribed

image text in transcribed

mport java.util.Scanner;

public class LA2a { /** * Number of digits in a valid value sequence */ public static final int SEQ_DIGITS = 10; /** * Error for an invalid sequence * (not correct number of characters * or not made only of digits) */ public static final String ERR_SEQ = "Invalid sequence"; /** * Error for an invalid pin * (not made entirely of * uppercase letters) */ public static final String ERR_PIN = "Invalid PIN"; /** * Converts an uppercase letter * to the corresponding number on * a standard phone... * * 1: * 2: ABC * 3: DEF * * 4: GHI * 5: JKL * 6: MNO * * 7: PQRS * 8: TUV * 9: WXYZ * * *: * 0: + * #: * * @param c assumed to be uppercase letter * @return corresponding phone number */ public static int letterToPhone(char c) { return 0; // replace with your code } /** * Takes an input PIN and produces a response * via first converting each character via phone * number, then using that as an index * to a value sequence * * @param pin input PIN (assumed to be uppercase letters) * @param values input value sequence * @return response */ public static int[] getResponse(String pin, int[] values) { int[] response = new int[pin.length()]; // write your code here return response; } /** * Returns true if the length of the * input string is equal to the input * parameter * * @param s input string * @param k length to check * @return true if length of string */ public static boolean stringIsKDigits(String s, int k) { return false; // replace with your code } /** * Returns true if all the characters * in the input string are '0' through '9' * * @param s input string * @return true if all characters in s are digits */ public static boolean allDigits(String s) { return false; // replace with your code } /** * Returns true if all the characters * in the input string are 'A' through 'Z' * * @param s input string * @return true if all characters are uppercase letters */ public static boolean allUppercaseLetters(String s) { return false; // replace with your code } /** * Converts a string of digits to an * array of integers (e.g. "12" -> {1, 2}) * * Assumes string is comprised of only digits! * * @param s digit string * @return corresponding integer array */ public static int[] digitStringToIntArray(String s) { return null; // replace with your code } /** * Returns how many times a value * occurs within an array * * @param value needle * @param values haystack * @return how many times the needle occurs in the haystack */ public static int countValues(int value, int[] values) { return 0; // replace with your code } /** * Returns how many ways the response could have been * produced from a given value sequence * * @param response output * @param values value sequence * @return how many PINs could have produced the same response given the value sequence */ public static int numPossible(int[] response, int[] values) { return 0; // replace with your code } /** * Inputs a value sequence and PIN, * outputs challenge response * * @param args command-line arguments, ignored */ public static void main(String[] args) { @SuppressWarnings("resource") final Scanner in = new Scanner(System.in); System.out.printf("Enter value sequence: "); final String seq = in.nextLine(); System.out.printf("Enter PIN: "); final String pin = in.nextLine(); // write your code here }

}

Problem a (LA2a.java) In this assignment you are to implement a challenge-response system to protect a user's numeric PIN which they will enter via a phone. First you will be supplied a 1o-digit numeric string (the challenge) Then, a PIN will be supplied as though typed into a phone 2 A B C DEF GHI J KL M NO PQRS TUV WXYZ So, "AGOT" would signify PIN 2468. To compute a response, substitute each PIN digit with the corresponding challenge digit. For example, assume this challenge (indexes shown for convenience) SEQUENCE 3 INDEX 2 2 2 0 2 8 If supplied GOT' via phone (PIN: 2468), you would respond 3121 (the value at index 2, followed by index 4,...). Note that the PIN can be any length (1 or more characters). Also note that if the challenge has repeated digits, the PIN itself is protected because many input PINs could have the same response (and future communications can use a different challenge) You will need to validate the challenge (10 all-digit characters) and the PIN (all digits) and then output the response. For example: Enter value sequence: 12345 Enter PIN: HELLO Invalid sequence Enter value sequence: 0.12345678 Enter PIN: HELLO Invalid sequence Enter value sequence: 0123456789 Enter PIN: Hello Invalid PIN Enter value sequence: 0123456789 Enter PIN: HELLO Response: 43556 Enter value sequence: 3231132213 Enter PIN: AGOT Response: 3121 To build up to this capability, you will have to implement several methods, each with their own tests. It is recommended that you first implement the following method: letterToPhone converts letters to numbers via the phone keypad and then proceed to getResponse computes the response given challenge & PIN followed by these helpers stringIsKDigits helps validate the challenge (is a string a specified length?) . . alDigits helps validate the challenge (is a string all digits?) . allUppercaseLettecs helps validate the PIN (is a string all uppercase letters?) . digitStringToIntArray helps access challenge digits via index in an array and then finally implement the main method to complete the program. Bonus While not required, there are two optional methods, each with their own tests, that can earn you extra points. The goal is to compute, for a given challenge, how many PINs would produce the same response. For example, given the challenge on page 1, 3121 could have been produced by 108 PINs (3 occurs four times in the challenge, 1 occurs three times, 2 occurs three times: 4x3x3 x3-108) santValuefinds how many times a digit s found within an array (i.e. the challenge) numPossible multiplies the counts from a full response

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

Write formal and informal proposals.

Answered: 1 week ago

Question

Describe the components of a formal report.

Answered: 1 week ago

Question

Write formal and informal reports.

Answered: 1 week ago