init
This commit is contained in:
BIN
ciphers/4as0ufZh9PpgbDEj0M0prBKp
Normal file
BIN
ciphers/4as0ufZh9PpgbDEj0M0prBKp
Normal file
Binary file not shown.
49
ciphers/Cipher.java
Normal file
49
ciphers/Cipher.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
// Represents a classical cipher that is able to encode a plaintext into a ciphertext, and
|
||||
// decode a ciphertext into a plaintext. Also capable of encoding and decoding entire files
|
||||
|
||||
public abstract class Cipher {
|
||||
// The minimum character able to be encoded by any cipher
|
||||
public static final int MIN_CHAR = (int)(' ');
|
||||
|
||||
// The maximum character able to be encoded by any cipher
|
||||
public static final int MAX_CHAR = (int)('}');
|
||||
|
||||
// The total number of characters able to be encoded by any cipher (aka. the encodable range)
|
||||
public static final int TOTAL_CHARS = MAX_CHAR - MIN_CHAR + 1;
|
||||
|
||||
// Pre: Throws a FileNotFoundException if a file with the provided 'fileName' doesn't exist
|
||||
// Post: Applies this Cipher's encryption scheme to the file with the given 'fileName', creating
|
||||
// a new file to store the results.
|
||||
public void encryptFile(String fileName) throws FileNotFoundException {
|
||||
fileHelper(fileName, true, "-encoded");
|
||||
}
|
||||
|
||||
// Pre: Throws a FileNotFoundException if a file with the provided 'fileName' doesn't exist
|
||||
// Post: Applies this Cipher's decryption scheme (reversing a single round of encryption if applied)
|
||||
// to the file with the given 'fileName', creating a new file to store the results.
|
||||
public void decryptFile(String fileName) throws FileNotFoundException {
|
||||
fileHelper(fileName, false, "-decoded");
|
||||
}
|
||||
|
||||
// Pre: Throws a FileNotFoundException if a file with the provided 'fileName' doesn't exist
|
||||
// Post: Reads from an input file with 'fileName', either encrypting or decrypting depending on 'encode',
|
||||
// printing the results to a new file with 'suffix' appended to the input file's name
|
||||
private void fileHelper(String fileName, boolean encode, String suffix) throws FileNotFoundException{
|
||||
Scanner sc = new Scanner(new File(fileName));
|
||||
String out = fileName.split("\\.txt")[0] + suffix + ".txt";
|
||||
PrintStream ps = new PrintStream(out);
|
||||
while(sc.hasNextLine()) {
|
||||
String line = sc.nextLine();
|
||||
ps.println(encode ? encrypt(line) : decrypt(line));
|
||||
}
|
||||
}
|
||||
|
||||
// Post: Returns the result of applying this Cipher's encryption scheme to 'input'
|
||||
public abstract String encrypt(String input);
|
||||
|
||||
// Post: Returns the result of applying this Cipher's decryption scheme to 'input'
|
||||
public abstract String decrypt(String input);
|
||||
}
|
||||
45
ciphers/Client.java
Normal file
45
ciphers/Client.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Client {
|
||||
// TODO: Change this line once you've implemented a cipher!
|
||||
public static final Cipher CHOSEN_CIPHER = null;
|
||||
|
||||
// (we also encourage you to change Cipher.MIN_CHAR and Cipher.MAX_CHAR when testing!)
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
Scanner console = new Scanner(System.in);
|
||||
System.out.println("Welcome to the CSE 123 cryptography application!");
|
||||
System.out.println("What would you like to do?");
|
||||
int chosen = -1;
|
||||
do {
|
||||
System.out.println();
|
||||
System.out.println("(1) Encode / (2) Decode a string");
|
||||
System.out.println("(3) Encode / (4) Decode a file");
|
||||
System.out.println("(5) Quit");
|
||||
System.out.print("Enter your choice here: ");
|
||||
|
||||
chosen = Integer.parseInt(console.nextLine());
|
||||
while (chosen < 1 || chosen > 5) {
|
||||
System.out.print("Please enter a valid option from above: ");
|
||||
chosen = Integer.parseInt(console.nextLine());
|
||||
}
|
||||
|
||||
if (chosen == 1 || chosen == 2) {
|
||||
System.out.println("Please enter the string you'd like to " +
|
||||
(chosen == 1 ? "encode" : "decode") + ": ");
|
||||
String input = console.nextLine();
|
||||
System.out.println(chosen == 1 ? CHOSEN_CIPHER.encrypt(input) :
|
||||
CHOSEN_CIPHER.decrypt(input));
|
||||
} else if (chosen == 3 || chosen == 4) {
|
||||
System.out.print("Please enter the name of the file you'd like to " +
|
||||
(chosen == 3 ? "encode" : "decode") + ": ");
|
||||
String fileName = console.nextLine();
|
||||
if (chosen == 3) {
|
||||
CHOSEN_CIPHER.encryptFile(fileName);
|
||||
} else {
|
||||
CHOSEN_CIPHER.decryptFile(fileName);
|
||||
}
|
||||
}
|
||||
} while (chosen != 5);
|
||||
}
|
||||
}
|
||||
11
ciphers/SubstitutionRandom.java
Normal file
11
ciphers/SubstitutionRandom.java
Normal file
@@ -0,0 +1,11 @@
|
||||
// TODO: Write your implementation to SubstitutionRandom here!
|
||||
import java.util.*;
|
||||
|
||||
public class SubstitutionRandom extends Substitution {
|
||||
public static void main(String[] args) {
|
||||
Random balls = new Random();
|
||||
int boner = balls.nextInt(4);
|
||||
System.out.println(boner);
|
||||
Collections.shuffle()
|
||||
}
|
||||
}
|
||||
19
ciphers/Testing.java
Normal file
19
ciphers/Testing.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import java.util.*;
|
||||
|
||||
public class Testing {
|
||||
|
||||
@Test
|
||||
@DisplayName("TODO: 1 Your Extension - ' '-'}' Shifter")
|
||||
public void thirdCaseTest() {
|
||||
assertTrue(false, "Not yet implemented!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("TODO: 1 Your Extension - ' '-'}' Shifter")
|
||||
public void thirdCaseTest() {
|
||||
assertTrue(false, "Not yet implemented!");
|
||||
}
|
||||
}
|
||||
1
ciphers/Transposition.java
Normal file
1
ciphers/Transposition.java
Normal file
@@ -0,0 +1 @@
|
||||
// TODO: Write your implementation to Transposition here!
|
||||
1
ciphers/Vigenere.java
Normal file
1
ciphers/Vigenere.java
Normal file
@@ -0,0 +1 @@
|
||||
// TODO: Write your implementation to Vigenere here!
|
||||
1
ciphers/files/ag.txt
Normal file
1
ciphers/files/ag.txt
Normal file
@@ -0,0 +1 @@
|
||||
HADBADCABBAGEBAG
|
||||
4463
ciphers/files/hamlet.txt
Normal file
4463
ciphers/files/hamlet.txt
Normal file
File diff suppressed because it is too large
Load Diff
15
ciphers/files/simple.txt
Normal file
15
ciphers/files/simple.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
Hi everyone,
|
||||
|
||||
We're using Ed Discussion for class Q&A.
|
||||
This is the best place to ask questions about the course, whether curricular or administrative. You will get faster answers here from staff and peers than through email.
|
||||
|
||||
Here are some tips:
|
||||
Search before you post
|
||||
Heart questions and answers you find useful
|
||||
Answer questions you feel confident answering
|
||||
Share interesting course related content with staff and peers
|
||||
|
||||
For more information on Ed Discussion, you can refer to the Quick Start Guide.
|
||||
|
||||
All the best this semester!
|
||||
Brett
|
||||
BIN
ciphers/lib/junit-platform-console-standalone-1.10.2.jar
Normal file
BIN
ciphers/lib/junit-platform-console-standalone-1.10.2.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user