Menu

[solved]-Code Skeleton Import Javautilscanner Public Class Encodinglab Public Static Final String C Q38986664

You will be writing a simple Java program that implements ROT-13 encryption. ROT-13 is a very simple encryption scheme that c

15.1: ENCODE A MESSAGE You will be writing a Java method that takes an arbitrary string as input, applies ROT13 to the string

Code Skeleton:

import java.util.Scanner;public class EncodingLab { public static final String CAPITALS = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; /** * Method that returns a string that is rot13 encoded from the input string. * * @param input * The string to encode * @return The input string with the rot13 algorithm applied to it */ public static String rot13(String input) { StringBuilder sb = new StringBuilder(); // TODO: Your code here. Your code MUST use the StringBuilder class // to build the String. return sb.toString(); } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print(“Enter a string to encode: “); String input = keyboard.nextLine(); String encoded = rot13(input); System.out.println(“Your string encoded is : ” + encoded); keyboard.close(); }}You will be writing a simple Java program that implements ROT-13 encryption. ROT-13 is a very simple encryption scheme that can be used to obfuscate text and is based on a very old encryption technique called a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a “shifted” alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ Shifted alphabet: DEFGHIJKLMNOPORSTUVWX Y ZABC Punctuation, numbers, and other non-alphabetic characters are unaffected by the shift. So the message “EAT AT JOE’S AT 1:00” becomes “HDW DW MRH’V 1:00”. ROT-13 is a special case of the Caesar cipher where the characters of the new alphabet are shifted (or “rotated”) by 13 positions from the original alphabet: Original alphabet: ABCDEFGHIJKLMNOPQRSTU V W X Y Z ROT-13 alphabet: NOPQRSTU V W X Y Z ABCDEFGHIJKLM So in the case of ROT-13, the message “EAT AT JOE’S AT 1:00” becomes “RNG NG WBR’E NG 1:00”. Unlike the general case of the Caesar cipher, ROT-13 has a special property that an encrypted message can be decrypted by applying ROT-13 a second time. So the message “RNG NG WBR’E NG 1:00” becomes “EAT AT JOE’S AT 1:00” when passed through a ROT-13 encryption. 15.1: ENCODE A MESSAGE You will be writing a Java method that takes an arbitrary string as input, applies ROT13 to the string, and displays the results in a specific format. The code must work for uppercase and lowercase letters and must work correctly if punctuation and numbers are included in the message. Use the code skeleton below to start your code. Create a new project and a new class named EncodingLab and paste the code skeleton into it. NOTE: If you haven’t noticed from the text above, only capital letters should have ROT-13 applied to them for this assignment. Anything else – punctuation, numbers, even lowercase letters – should be left untouched. You can use the functions Character.isLetter) and Character.is UpperCase() to test if a character is an uppercase letter or not. boolean test1 = Character.isLetter(‘A’); // test1 will be true boolean test2 = Character.isUpperCase(‘A’); // test2 will be true boolean test3 = Character.isLetter(‘?’); // tests will be false boolean test4 = Character.isUpperCase(‘a’); // test will be false NOTE 2: This lab requires you to change characters based on changing individual characters. While there are many ways to do this, some will be easier than others. One way to do this easily is to take advantage of a String constant with all of the letters in a single String in order: public final String CAPITALS = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; With this setup, each character is represented as a numeric value by its index in the String, and we can manipulate the characters using simple math. For example, this code snippet should display the letter ‘B’: int myA = CAPITALS.indexOf(“A”); int my B = myA+1; char let = CAPITALS.charAt(myB); System.out.println(let); NOTE: You cannot just add 13 to every index to get the ROT-13 value-adding 13 to the index value for the letter ‘Z’ gives you an index of 38, which is outside the bounds of the String. You will need to implement the logic to allow your characters to “wrap around” yourself. There are many different ways you can approach this, but as a hint consider using the remainder operation (%) to get your indices to circle back around. The constant CAPITALS is already included in the code skeleton provided in the link above as a public static variable for the class – remember, variables declared in the class body like this can be accessed by any method in the class (ie, their scope is the entire class, not just a single method in the class). Show transcribed image text You will be writing a simple Java program that implements ROT-13 encryption. ROT-13 is a very simple encryption scheme that can be used to obfuscate text and is based on a very old encryption technique called a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a “shifted” alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ Shifted alphabet: DEFGHIJKLMNOPORSTUVWX Y ZABC Punctuation, numbers, and other non-alphabetic characters are unaffected by the shift. So the message “EAT AT JOE’S AT 1:00” becomes “HDW DW MRH’V 1:00”. ROT-13 is a special case of the Caesar cipher where the characters of the new alphabet are shifted (or “rotated”) by 13 positions from the original alphabet: Original alphabet: ABCDEFGHIJKLMNOPQRSTU V W X Y Z ROT-13 alphabet: NOPQRSTU V W X Y Z ABCDEFGHIJKLM So in the case of ROT-13, the message “EAT AT JOE’S AT 1:00” becomes “RNG NG WBR’E NG 1:00”. Unlike the general case of the Caesar cipher, ROT-13 has a special property that an encrypted message can be decrypted by applying ROT-13 a second time. So the message “RNG NG WBR’E NG 1:00” becomes “EAT AT JOE’S AT 1:00” when passed through a ROT-13 encryption.
15.1: ENCODE A MESSAGE You will be writing a Java method that takes an arbitrary string as input, applies ROT13 to the string, and displays the results in a specific format. The code must work for uppercase and lowercase letters and must work correctly if punctuation and numbers are included in the message. Use the code skeleton below to start your code. Create a new project and a new class named EncodingLab and paste the code skeleton into it. NOTE: If you haven’t noticed from the text above, only capital letters should have ROT-13 applied to them for this assignment. Anything else – punctuation, numbers, even lowercase letters – should be left untouched. You can use the functions Character.isLetter) and Character.is UpperCase() to test if a character is an uppercase letter or not. boolean test1 = Character.isLetter(‘A’); // test1 will be true boolean test2 = Character.isUpperCase(‘A’); // test2 will be true boolean test3 = Character.isLetter(‘?’); // tests will be false boolean test4 = Character.isUpperCase(‘a’); // test will be false NOTE 2: This lab requires you to change characters based on changing individual characters. While there are many ways to do this, some will be easier than others. One way to do this easily is to take advantage of a String constant with all of the letters in a single String in order: public final String CAPITALS = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; With this setup, each character is represented as a numeric value by its index in the String, and we can manipulate the characters using simple math. For example, this code snippet should display the letter ‘B’: int myA = CAPITALS.indexOf(“A”); int my B = myA+1; char let = CAPITALS.charAt(myB); System.out.println(let); NOTE: You cannot just add 13 to every index to get the ROT-13 value-adding 13 to the index value for the letter ‘Z’ gives you an index of 38, which is outside the bounds of the String. You will need to implement the logic to allow your characters to “wrap around” yourself. There are many different ways you can approach this, but as a hint consider using the remainder operation (%) to get your indices to circle back around. The constant CAPITALS is already included in the code skeleton provided in the link above as a public static variable for the class – remember, variables declared in the class body like this can be accessed by any method in the class (ie, their scope is the entire class, not just a single method in the class).

Expert Answer


Answer to Code Skeleton: import java.util.Scanner; public class EncodingLab { public static final String CAPITALS = “ABCDEFGHIJKLM… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *