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

Finished lab #3

Open
wants to merge 4 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
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,30 @@
hs_err_pid*

.idea/

# Apple files
*.DS_Store
.AppleDouble
.LSOverride

/target/
.classpath
.project
.settings


# User-specific stuff:
*.iml
.idea/**
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
32 changes: 0 additions & 32 deletions Crypto/src/ROT13.java

This file was deleted.

88 changes: 88 additions & 0 deletions Crypto/src/main/java/ROT13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import java.sql.SQLOutput;
import java.util.Map;
import java.util.TreeMap;

public class ROT13 {

Map<String, String> upperCaseMap = new TreeMap<>();
Map<String, String> lowerCaseMap = new TreeMap<>();

ROT13(Character cs, Character cf) {
populateMap();
}

ROT13() {
new ROT13('a', 'n');
}


public String crypt(String text) throws UnsupportedOperationException {

return encrypt(text);
}

public String encrypt(String text) {
char[] sTemp = text.toCharArray();
String result = "";


for (int i = 0; i < sTemp.length; i++) {
if (getCharNumericValue(sTemp[i]) > 64 && getCharNumericValue(sTemp[i]) < 91) {
//upper case
result = result.concat(upperCaseMap.get(Character.toString(sTemp[i])));
} else if (getCharNumericValue(sTemp[i]) > 96 && getCharNumericValue(sTemp[i]) < 122) {
//lower case
result = result.concat(lowerCaseMap.get(Character.toString(sTemp[i])));
} else {
result = result.concat(getCharacterValue(getCharNumericValue(sTemp[i])).toString());
}
}
return result;
}

public String decrypt(String text) {
String result = encrypt(text);
return result;
}

public static String rotate(String s, Character c) {
String[] temp = s.split("");
String result = "";
int location = s.indexOf(c);

for (int i = 0; i < temp.length; i++) {
if (i < location) {
result = result.concat(temp[location + i]);

} else {
result = result.concat(temp[Math.abs(i - location)]);
}
}
return result;
}

private void populateMap() {
String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String s2 = s1.toLowerCase();

String[] tempUpper = s1.split("");
String[] rotatedUpper = rotate(s1, 'N').split("");

String[] tempLower = s2.split("");
String[] rotatedLower = rotate(s2, 'n').split("");

for (int i = 0; i < tempUpper.length; i++) {
this.upperCaseMap.put(tempUpper[i], rotatedUpper[i]);
this.lowerCaseMap.put(tempLower[i], rotatedLower[i]);
}

}

public Integer getCharNumericValue(final char character) {
return (int) character;
}

public Character getCharacterValue(final int ascii) {
return (char) ascii;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void rotateStringTest2() {
System.out.println(actual);
// Then
assertTrue(actual.equals(s2));

}

@Test
Expand Down Expand Up @@ -88,4 +89,5 @@ public void cryptTest2() {
assertTrue(actual.equals(Q1));
}


}
16 changes: 16 additions & 0 deletions SimpleCrypt.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Crypto/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Crypto/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,19 @@
<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>