From dd5b6e11a025256428eaf666798a946ffbf6cbe1 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 16 Nov 2019 12:46:04 -0500 Subject: [PATCH 1/4] create structure --- .gitignore | 27 +++++++++++++++++++++++ Crypto/src/{ => main/java}/ROT13.java | 4 ---- Crypto/src/{ => test/java}/ROT13Test.java | 0 SimpleCrypt.iml | 13 +++++++++++ pom.xml | 8 +++++++ 5 files changed, 48 insertions(+), 4 deletions(-) rename Crypto/src/{ => main/java}/ROT13.java (74%) rename Crypto/src/{ => test/java}/ROT13Test.java (100%) create mode 100644 SimpleCrypt.iml diff --git a/.gitignore b/.gitignore index 5f96b60..e2ebfae 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/Crypto/src/ROT13.java b/Crypto/src/main/java/ROT13.java similarity index 74% rename from Crypto/src/ROT13.java rename to Crypto/src/main/java/ROT13.java index 1c58731..14cc6fb 100644 --- a/Crypto/src/ROT13.java +++ b/Crypto/src/main/java/ROT13.java @@ -1,7 +1,3 @@ -import static java.lang.Character.isLowerCase; -import static java.lang.Character.isUpperCase; -import static java.lang.Character.toLowerCase; - public class ROT13 { ROT13(Character cs, Character cf) { diff --git a/Crypto/src/ROT13Test.java b/Crypto/src/test/java/ROT13Test.java similarity index 100% rename from Crypto/src/ROT13Test.java rename to Crypto/src/test/java/ROT13Test.java diff --git a/SimpleCrypt.iml b/SimpleCrypt.iml new file mode 100644 index 0000000..0313410 --- /dev/null +++ b/SimpleCrypt.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4021c2d..47fe983 100644 --- a/pom.xml +++ b/pom.xml @@ -8,5 +8,13 @@ SimpleCrypt 1.0-SNAPSHOT + + + junit + junit + 4.12 + test + + From 20757ce289f58f356297e1c8f836f7415a2b942a Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 16 Nov 2019 12:47:27 -0500 Subject: [PATCH 2/4] Add junit --- SimpleCrypt.iml | 1 + pom.xml | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/SimpleCrypt.iml b/SimpleCrypt.iml index 0313410..5d92679 100644 --- a/SimpleCrypt.iml +++ b/SimpleCrypt.iml @@ -5,6 +5,7 @@ + diff --git a/pom.xml b/pom.xml index 47fe983..206a707 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,12 @@ 4.12 test + + junit + junit + 4.12 + test + From e77c4f1060d2f16bec30ee86783e91cfd58cd910 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 16 Nov 2019 14:16:00 -0500 Subject: [PATCH 3/4] Add logic for rotate --- Crypto/src/main/java/ROT13.java | 27 +++++++++++++++++++++++++-- Crypto/src/test/java/ROT13Test.java | 1 + SimpleCrypt.iml | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Crypto/src/main/java/ROT13.java b/Crypto/src/main/java/ROT13.java index 14cc6fb..6d3a360 100644 --- a/Crypto/src/main/java/ROT13.java +++ b/Crypto/src/main/java/ROT13.java @@ -1,9 +1,13 @@ -public class ROT13 { +import java.sql.SQLOutput; + +public class ROT13 { + ROT13(Character cs, Character cf) { } ROT13() { + new ROT13('a', 'n'); } @@ -21,8 +25,27 @@ public String decrypt(String text) { } 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; + } - return ""; + + public Integer getCharNumericValue(final char character) { + return (int) character; } + public Character getCharacterValue(final int ascii) { + return (char) ascii; + } } diff --git a/Crypto/src/test/java/ROT13Test.java b/Crypto/src/test/java/ROT13Test.java index 400c38b..2fe5ce5 100644 --- a/Crypto/src/test/java/ROT13Test.java +++ b/Crypto/src/test/java/ROT13Test.java @@ -88,4 +88,5 @@ public void cryptTest2() { assertTrue(actual.equals(Q1)); } + } \ No newline at end of file diff --git a/SimpleCrypt.iml b/SimpleCrypt.iml index 5d92679..79ee65f 100644 --- a/SimpleCrypt.iml +++ b/SimpleCrypt.iml @@ -10,5 +10,7 @@ + + \ No newline at end of file From be7a6efc751d1e45af21a8d72be1791732cb54fc Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 16 Nov 2019 15:00:45 -0500 Subject: [PATCH 4/4] Finished lab --- Crypto/src/main/java/ROT13.java | 53 ++++++++++++++++++++++++----- Crypto/src/test/java/ROT13Test.java | 1 + SimpleCrypt.iml | 2 +- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Crypto/src/main/java/ROT13.java b/Crypto/src/main/java/ROT13.java index 6d3a360..34b486b 100644 --- a/Crypto/src/main/java/ROT13.java +++ b/Crypto/src/main/java/ROT13.java @@ -1,9 +1,14 @@ import java.sql.SQLOutput; +import java.util.Map; +import java.util.TreeMap; public class ROT13 { + Map upperCaseMap = new TreeMap<>(); + Map lowerCaseMap = new TreeMap<>(); ROT13(Character cs, Character cf) { + populateMap(); } ROT13() { @@ -13,15 +18,31 @@ public class ROT13 { public String crypt(String text) throws UnsupportedOperationException { - return ""; + return encrypt(text); } public String encrypt(String text) { - return 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) { - return text; + String result = encrypt(text); + return result; } public static String rotate(String s, Character c) { @@ -30,16 +51,32 @@ public static String rotate(String s, Character c) { int location = s.indexOf(c); for (int i = 0; i < temp.length; i++) { - if (i < location) { - result = result.concat(temp[location + i]); + if (i < location) { + result = result.concat(temp[location + i]); - } else { - result = result.concat(temp[Math.abs(i - location)]); - } + } 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; diff --git a/Crypto/src/test/java/ROT13Test.java b/Crypto/src/test/java/ROT13Test.java index 2fe5ce5..a04e8f4 100644 --- a/Crypto/src/test/java/ROT13Test.java +++ b/Crypto/src/test/java/ROT13Test.java @@ -46,6 +46,7 @@ public void rotateStringTest2() { System.out.println(actual); // Then assertTrue(actual.equals(s2)); + } @Test diff --git a/SimpleCrypt.iml b/SimpleCrypt.iml index 79ee65f..cc4985d 100644 --- a/SimpleCrypt.iml +++ b/SimpleCrypt.iml @@ -1,6 +1,6 @@ - +