Question

Consider the encryption code  Encryption Code true false - stringContains is an encryption algorithm that can be...

Consider the encryption code  Encryption Code

true false - stringContains is an encryption algorithm that can be decrpyted
true false - Running reverseString twice will have no effect
true false - Running incLetters(s,4) then incLetters(s,-4) will have no effect
true false - using maxDigit as an encryption algorighm, it can be decrypted

USE CODE BELOW:

package encryption;
import java.util.Scanner;
public class Encryption {
    public static void main(String[] args) {
        Scanner scanner = new Scanner (System.in);
        String password, encryptedPassword, salt;
        int increment;
        System.out.print("Enter string to encrypt: ");  password = scanner.next();
        System.out.print("Enter encruption salt  : ");  salt     = scanner.next();
        increment = EncryptAlgos.maxDigit(salt);
        if (EncryptAlgos.stringContains(salt,"d")) { increment = increment * (-1); }
        encryptedPassword = EncryptAlgos.incLetters(password, increment);
        encryptedPassword = EncryptAlgos.reverseLetters(encryptedPassword);
        System.out.println("Encrypted string: " + encryptedPassword);
    }  
}
class EncryptAlgos {  // library of encryption algorityms
    public static String incLetters(String s, int amount) {
        String es = "";
        for(int i=0;i<s.length();i++) { es+=(char)(s.charAt(i)+amount); }
        return es;
    }
    public static String reverseLetters(String s) {
        String es = "";
        for(int i=s.length()-1;i >=0;i--) { es = es + s.charAt(i); }
        return es;
    }
    public static int maxDigit(String s) {
        int max = 1; int num;
        for(int i=0; i<s.length();i++) { 
            num = Character.getNumericValue(s.charAt(i));
            if (num > 0 && num < 10 && num > max) { max = num;}
        }
        return max;
    }
    public static boolean stringContains(String s, String c) {
        return s.contains(c);
    }    
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

stringContains is an encryption algorithm that can be decrpyted

False

Description: stringContains method only checks whether salt contains string "d" or not, it is not any encryption algorithm independently.


Running reverseString twice will have no effect

False

Description: If reverseString ran twice, the encryption string changes and it is not similar to when it ran once.

reverseString once:

Enter string to encrypt: abcd
Enter encruption salt : bcd
Encrypted string: cba`

reverseString twice:

Enter string to encrypt: abcd
Enter encruption salt : bcd
Encrypted string: `abc


Running incLetters(s,4) then incLetters(s,-4) will have no effect

False

Description: Running incLetters(s,4) then incLetters(s,-4) will give different results of encryption.


using maxDigit as an encryption algorighm, it can be decrypted

True

Description: using maxDigit as an encryption algorighm, it can be decrypted because it's logic is just to calculate maximum digit on loop.

Add a comment
Know the answer?
Add Answer to:
Consider the encryption code  Encryption Code true false - stringContains is an encryption algorithm that can be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please fix my code so I can get this output: Enter the first 12-digit of an...

    Please fix my code so I can get this output: Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number is 9780132130806 This was my output: import java.util.Scanner; public class Isbn { private static int getChecksum(String s) { // Calculate checksum int sum = 0; for (int i = 0; i < s.length(); i++) if (i % 2 == 0) sum += (s.charAt(i) - '0') * 3; else sum += s.charAt(i) - '0'; return 10...

  • 10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (...

    10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ] else if (s.charAt (i)'t') System.out.print (s.charAt (i-2)) i+ti else System. out. print (s . charAt (İ) ) ; if (i<2) System.out.print ("y"); System.out.println () 10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ]...

  • 10. What prints when the following code is executed? public static void main (String args) "Cattywampus";...

    10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ] else if (s.charAt (i)'t') System.out.print (s.charAt (i-2)) i+ti else System. out. print (s . charAt (İ) ) ; if (i<2) System.out.print ("y"); System.out.println ()

  • Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string),...

    Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string), findFirstP(finds first p in a string)) in java language. public class simpleLoops { /** * @param args */ public static void main(String[] args) {    System.out.println(longestRun("aabbbccd"));    System.out.println("Expected 3");    System.out.println(longestRun("aaa"));    System.out.println("Expected 3");    System.out.println(longestRun("aabbbb"));    System.out.println("Expected 4");          int count = countP("Mississippi"); System.out.println(count);    int result = findLastP("Mississippi"); System.out.println(result); result = findFirstP("stop"); System.out.println(result); result = findFirstP("xxxyyyzzz"); System.out.println(result); } /** *...

  • Given the following code: public static void foo3(String s) { if (s.length() >0) { System.out.print(s.charAt(s.length() -1));...

    Given the following code: public static void foo3(String s) { if (s.length() >0) { System.out.print(s.charAt(s.length() -1)); foo3(s.substring(0, s.length() -1)); } } What is the output of: foo3(“”); 2, You coded the following in the file Test.java : System.out.println( foo(5)); //more code here public static int foo(int n) //line 9 { if (n = = 0)    return 1; else    System.out.println(n* foo(n-1) ); }                                    //line 15 At compile time, you get the following error: Text.java: 15: missing return statement }                                ...

  • instructions These questions should test if you have understood the contents of Chapter 18 "Recursion". 1....

    instructions These questions should test if you have understood the contents of Chapter 18 "Recursion". 1. What will this method return if you call it this: xMethod (4) static int xMethod (int n) { if (n == 1) return 1; else return n + xMethod (n - 1); } 1. 10 2. 11 3. 12 4. 9 2. Analyze the following code: public class Test { public static void main (String [] args) { int [] x = {1, 2,...

  • I am given an input file, P1input.txt and I have to write code to find the...

    I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 {    public static...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Step 4: Add code that discards any extra entries at the propmt that asks if you...

    Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question:       "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...

  • Background An anagram is a word phrase, or name formed by rearranging the letters of another,...

    Background An anagram is a word phrase, or name formed by rearranging the letters of another, such as the word "cinema", formed from 'iceman". Problem Statement Given two strings s and t, write a function to determine ift is an anagram of S. A sample main function is provided so that you may test your code on sample inputs. Inputs can be provided in the box below your code, please format your input as follows: Example input nose soen Requirements...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT