diff --git a/Crypto/src/ROT13Test.java b/Crypto/Test/ROT13Test.java
similarity index 71%
rename from Crypto/src/ROT13Test.java
rename to Crypto/Test/ROT13Test.java
index 400c38b..8d725ac 100644
--- a/Crypto/src/ROT13Test.java
+++ b/Crypto/Test/ROT13Test.java
@@ -1,5 +1,9 @@
+import org.junit.Assert;
import org.junit.Test;
+import java.io.File;
+import java.io.IOException;
+
import static org.junit.Assert.*;
public class ROT13Test {
@@ -88,4 +92,25 @@ public void cryptTest2() {
assertTrue(actual.equals(Q1));
}
+ @Test
+ public void encryptFileTest() throws IOException {
+ File file = new File("/Users/brandonchambers/week5/SimpleCrypt/sonnet18.txt");
+ ROT13 test = new ROT13();
+
+ String expected = "Gubh neg zber ybiryl naq zber grzcrengr:\n" +
+ "Naq fhzzre’f yrnfr ungu nyy gbb fubeg n qngr;\n" +
+ "Naq bsgra vf uvf tbyq pbzcyrkvba qvzz'q;\n" +
+ "Ol punapr be angher’f punatvat pbhefr hagevzz'q;\n" +
+ "Abe ybfr cbffrffvba bs gung snve gubh bj’fg;\n" +
+ "Jura va rgreany yvarf gb gvzr gubh tebj’fg:\n" +
+ " Fb ybat yvirf guvf, naq guvf tvirf yvsr gb gurr." + "\n";
+
+
+ String actual = test.encrpytFile();
+
+ Assert.assertEquals(expected, actual);
+
+
+ }
+
}
\ No newline at end of file
diff --git a/Crypto/src/ROT13.java b/Crypto/src/ROT13.java
index 1c58731..3bea069 100644
--- a/Crypto/src/ROT13.java
+++ b/Crypto/src/ROT13.java
@@ -1,10 +1,18 @@
+import java.io.*;
+import java.util.NoSuchElementException;
+import java.util.Scanner;
+
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Character.toLowerCase;
public class ROT13 {
+ int hi;
+
ROT13(Character cs, Character cf) {
+ hi = cf.compareTo(cs);
+
}
ROT13() {
@@ -13,20 +21,111 @@ public class ROT13 {
public String crypt(String text) throws UnsupportedOperationException {
- return "";
+ return encrypt(text);
}
-
+ //This method is working as needed
public String encrypt(String text) {
- return text;
+
+ char[] str = text.toCharArray();
+ for (int i = 0; i < str.length; i++) {
+ char letter = str[i];
+
+ if (letter >= 'a' && letter <= 'z') {
+
+
+ if (letter > 'm') {
+ letter -= 13;
+ } else {
+ letter += 13;
+ }
+ } else if (letter >= 'A' && letter <= 'Z') {
+
+
+ if (letter > 'M') {
+ letter -= 13;
+ } else {
+ letter += 13;
+ }
+ }
+ str[i] = letter;
+ }
+
+ System.out.println(new String(str));
+ return new String(str);
}
+ //This method is working as needed
public String decrypt(String text) {
- return text;
- }
+ return encrypt(text);
+ }
+ //This method is working as needed
public static String rotate(String s, Character c) {
- return "";
+ if(s.charAt(0) == c){
+ return s;
+ }
+
+ StringBuilder result = new StringBuilder();
+ int count = c.compareTo(s.charAt(0));
+ for(int i = 0; i < s.length(); i++){
+ char letter;
+ if(i + count < s.length()){
+ letter = s.charAt(i + count);
+ }
+ else {
+ letter = s.charAt(i + count - s.length());
+ }
+ result.append(letter);
+ }
+ return result.toString();
}
+ //ROT OBJECT crpyt this file
+ //file = new File("sonnet18.txt");
+
+//Instantiate ROT13 and take in a file to be encrypted
+ public String encrpytFile() throws IOException, NoSuchElementException {
+ ROT13 rot = new ROT13();
+
+ StringBuilder output = new StringBuilder();
+ String fileName = "sonnet18.enc";
+ try {
+ File f = new File("/Users/brandonchambers/week5/SimpleCrypt/sonnet18.txt");
+ BufferedWriter op = new BufferedWriter(new FileWriter(fileName));
+
+ Scanner out = new Scanner(f);
+
+
+ while ((out.nextLine()) != null) {
+ output.append(out.nextLine() + "\n");
+ }
+ op.write(rot.crypt(output.toString()));
+ op.close();
+ }
+ catch (NoSuchElementException noSuchException){
+
+ }
+ catch (IOException ioException){ } {
+
+ }
+
+ return rot.crypt(output.toString());
+ }
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Crypto/src/main.java b/Crypto/src/main.java
new file mode 100644
index 0000000..03c367f
--- /dev/null
+++ b/Crypto/src/main.java
@@ -0,0 +1,10 @@
+public class main {
+
+ public static void main(String[] args) {
+ ROT13 test = new ROT13();
+
+ test.encrypt("");
+
+ }
+}
+
diff --git a/pom.xml b/pom.xml
index 4021c2d..e3815ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,14 @@
com.zipcodewilmington
SimpleCrypt
1.0-SNAPSHOT
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
diff --git a/sonnet18.enc b/sonnet18.enc
new file mode 100644
index 0000000..e69de29