1) Convert the following string to its ASCII values: "I never saw a purple cow" ```java String poem = "I never saw a purple cow"; for(int i = 0; i < poem.length(); i++) { System.out.println((int)poem.charAt(i)); } ``` 2) If a = 1, b=2, c=3… convert the following String to its equivalent character codes: "DailyJava" ```java String poem = "DailyJava"; poem = poem.toUpperCase(); for(int i = 0; i < poem.length(); i++) { System.out.println((int)poem.charAt(i)-64); } ``` 3) ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher, developed in ancient Rome. Write a program that will accept a String as input then output that string under a ROT13 transformation, so input of HELLO will result in output of URYYB String poem = "I never saw a purple cow"; poem = poem.toUpperCase(); ```java for(int i = 0; i < poem.length(); i++) { int ascii = poem.charAt(i); if (ascii == 32) { System.out.println(" "); } else { ascii -= 51; // -64 + 13 if (ascii > 26) ascii = ascii - 26; System.out.println((char) (ascii + 64)); } } ``` 4) Write a ROT-N cipher, similar to a ROT13 cipher, where a string and a shift are input, and a string is outputted with the characters shifted by N, so if the input is "DAD" and 1, the output is "EBE" ```java Scanner scan = new Scanner(System.in); System.out.println("Enter String"); String poem = scan.nextLine(); poem = poem.toUpperCase(); System.out.println("Enter shift"); int shift = scan.nextInt(); for(int i = 0; i < poem.length(); i++) { int ascii = poem.charAt(i); if (ascii == 32) { System.out.println(" "); } else { ascii = ascii - 64 + shift; if (ascii > 26) ascii = ascii - 26; System.out.println((char) (ascii + 64)); } } ``` 5) Write a program that uses ASCII values to convert lowercase characters to uppercase, so input of "this" will result in output of "THIS". DO NOT use library methods such as toUpperCase() ```java String lower = "this"; String upper = ""; for(int i = 0; i < lower.length(); i++) { char c = lower.charAt(i); if(c < 97 || c > 122) { upper = upper + c; } else { upper = upper + (char)(c -32); } } System.out.println(upper); ``` 6) There are 62 Alphanumeric Characters: [A-Za-z0-9]. Any other character, such as %,(): is non-alphanumeric. There are also a number of control or non-printing characters. These include Line Feed, Carriage Return and Tab. Write a program that imports a text file and prints the number of alphanumeric characters it contains. ```java String alpha = "As simple as, do re mi, A B C, 1 2 3"; int alphaCount = 0; for(int i = 0; i < alpha.length(); i++) { if (alpha.substring(i, i+1).matches("[a-zA-Z0-9]")) alphaCount++; } System.out.println(alphaCount); ``` 7) Write a program that accepts a string cipher as an input and ouputs a string plaintext containing every second letter from input. Test your program using the input "Knives" and "Forks". You should get the output "nvs" and "ok" respectively ```java String cipher = "knives"; String plaintext = ""; for(int i = 1; i < cipher.length(); i+=2) { plaintext = plaintext + cipher.charAt(i); } System.out.println(plaintext); ```