Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions Crypto/src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,40 @@ public class Main {



public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
System.out.printf("Please enter the key. (How many places you want each letter to shift):"); //Added custom number shift
String key = input.nextLine();
try {
Integer.parseInt(key);
try {
if ((Integer.parseInt(key) > 26) || 0 > (Integer.parseInt(key))) {
System.out.println("Invalid Range");
System.exit(0);
}
} catch (NumberFormatException e) {
System.out.println("It needs to be a number. ");
}
}catch (Exception e) {
System.out.println("An unknown error has occured");
}


int keys = Integer.parseInt(key);


InputStream in = new FileInputStream("sonnet18.txt");
String body = IOUtils.toString(in, StandardCharsets.UTF_8.name());
System.out.println(body);
System.out.printf("\n\nNormal: \n\n%s\n\n", body); // Added formatting for user accessibility
PrintStream out = new PrintStream(new FileOutputStream("sonnet18.enc"));
ROT13 rot13 = new ROT13();
ROT13 rot13 = new ROT13(keys);
String output = rot13.encrypt(body);
System.out.printf("Encrypted:\n\n%s\n\n", output); // Shows the output/ result of the encryption
out.append(output);
out.flush();
}
}





}}
6 changes: 3 additions & 3 deletions Crypto/src/ROT13.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class ROT13 {
this.shift = temp;
}

ROT13() {
this.shift = 13;
}
ROT13(int key) {
this.shift = key;
} //Takes in a user number for how many places the letter should shift

public String crypt(String text) throws UnsupportedOperationException {
return crypt(text, shift);
Expand Down