Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions Crypto/src/ROT13Test.java → Crypto/Test/ROT13Test.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);


}

}
111 changes: 105 additions & 6 deletions Crypto/src/ROT13.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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());
}
}
















10 changes: 10 additions & 0 deletions Crypto/src/main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class main {

public static void main(String[] args) {
ROT13 test = new ROT13();

test.encrypt("");

}
}

8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>SimpleCrypt</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
Empty file added sonnet18.enc
Empty file.