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
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package ROT13;


import org.junit.Test;

import static org.junit.Assert.*;
Expand All @@ -23,7 +26,7 @@ public void rotateStringTest0() {
public void rotateStringTest1() {
// Given
String s1 = "ABCDEF";
String s2 = "DEFABC";
String s2 = "DEFABC"; //DEFGHI

// When
ROT13 cipher = new ROT13();
Expand Down
32 changes: 0 additions & 32 deletions Crypto/src/ROT13.java

This file was deleted.

6 changes: 6 additions & 0 deletions Crypto/src/java/ROT13/PrintFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ROT13;

public class PrintFile {


}
61 changes: 61 additions & 0 deletions Crypto/src/java/ROT13/ROT13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ROT13;

import java.util.Arrays;

import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Character.toLowerCase;

public class ROT13 {
protected String startUpper;
protected String startLower;
protected String registerUpper;
protected String registerLower;
private Boolean symmetric = false;
private Integer shift;

ROT13(Character cs, Character cf) {
shift = cf - cs;
}

ROT13() {
this('a', 'm');
}


public String crypt(String text) throws UnsupportedOperationException {
//if (this.symmetric != true) throw new UnsupportedOperationException();


StringBuilder sb = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char c =text.charAt(i);
if (c >= 'a' && c <= 'm') c += 13;
else if (c >= 'A' && c <= 'M') c += 13;
else if (c >= 'n' && c <= 'z') c -= 13;
else if (c >= 'N' && c <= 'Z') c -= 13;
sb.append(c);
}
return sb.toString();
}


public String encrypt(String text)
{
return crypt(text);
}

public String decrypt(String text) {

return crypt(text);
}

public static String rotate(String s, Character c) {
Integer index = s.indexOf(c);
String front = s.substring(index);
String back = s.substring(0, index);
String joined = front + back;
return joined;
}

}
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
<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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>