diff --git a/Crypto/src/Main.java b/Crypto/src/Main.java new file mode 100644 index 0000000..42bd962 --- /dev/null +++ b/Crypto/src/Main.java @@ -0,0 +1,18 @@ +import org.apache.commons.io.IOUtils; + +import java.io.*; +import java.nio.charset.StandardCharsets; + +public class Main { + + public static void main(String[] args) throws IOException { + InputStream in = new FileInputStream("sonnet18.txt"); + String body = IOUtils.toString(in, StandardCharsets.UTF_8.name()); + System.out.println(body); + PrintStream out = new PrintStream(new FileOutputStream("sonnet18.enc")); + ROT13 rot13 = new ROT13(); + String output = rot13.encrypt(body); + out.append(output); + out.flush(); + } +} \ No newline at end of file diff --git a/Crypto/src/ROT13.java b/Crypto/src/ROT13.java index 1c58731..048934e 100644 --- a/Crypto/src/ROT13.java +++ b/Crypto/src/ROT13.java @@ -3,30 +3,77 @@ import static java.lang.Character.toLowerCase; public class ROT13 { + private Character cs; + private Character cf; ROT13(Character cs, Character cf) { + this.cs = cs; + this.cf = cf; } ROT13() { + this.cs = 'a'; + this.cf = 'a' + 13; } public String crypt(String text) throws UnsupportedOperationException { + String crypted = ""; + for(int i = 0; i= 'a' && textChar <= 'z'){ + differenceFromLastChar = 'z'-textChar; + if(differenceFromLastChar > shiftDifferences){ + textChar += shiftDifferences; + } + else + { + textChar = 'a'; + textChar +=(shiftDifferences - differenceFromLastChar-1); + } + } + else if(textChar >= 'A'&& textChar <= 'Z'){ + differenceFromLastChar = 'Z'-textChar; + if(differenceFromLastChar > shiftDifferences){ + textChar += shiftDifferences; + }else { + textChar = 'A'; + textChar +=(shiftDifferences-differenceFromLastChar-1); + } + } + crypted += textChar; + } - return ""; + return crypted; } public String encrypt(String text) { - return text; + return crypt(text); } public String decrypt(String text) { - return text; + return crypt(text); } public static String rotate(String s, Character c) { + char lastChar = s.charAt(s.length()-1); + String rotated = ""; + for(int i = 0; i< s.length();i++){ + char textChar = s.charAt(i); + int shiftDifferences = c - 'A'; + int differenceFromLastChar = lastChar - textChar; + if(differenceFromLastChar >= shiftDifferences){ - return ""; + textChar += shiftDifferences; + }else { + textChar = 'A'; + textChar += (shiftDifferences -differenceFromLastChar-1); + } + rotated +=textChar; + } + return rotated; } } diff --git a/SimpleCrypt.iml b/SimpleCrypt.iml new file mode 100644 index 0000000..8875a0d --- /dev/null +++ b/SimpleCrypt.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4021c2d..8a72b8d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,23 @@ com.zipcodewilmington SimpleCrypt 1.0-SNAPSHOT + + + commons-io + commons-io + 2.5 + + + junit + junit + 4.13.1 + compile + + + + 1.8 + 1.8 + diff --git a/sonnet18.enc b/sonnet18.enc new file mode 100644 index 0000000..3567ebb --- /dev/null +++ b/sonnet18.enc @@ -0,0 +1,14 @@ +Funyy V pb`cner gurr gb n fh``re’f qnl? +Gubh neg `ber ybiryl naq `ber gr`crengr: +Ebhtu jvaqf qb funxr gur qneyvat ohqf bs @nl, +Naq fh``re’f yrnfr ungu nyy gbb fubeg n qngr; +Fb`rgv`r gbb ubg gur rlr bs urnira fuvarf, +Naq bsgra vf uvf tbyq pb`cyrkvba qv``'q; +Naq rirel snve seb` snve fb`rgv`r qrpyvarf, +Ol punapr be angher’f punatvat pbhefr hagev``'q; +Ohg gul rgreany fh``re funyy abg snqr, +Abe ybfr cbffrffvba bs gung snve gubh bj’fg; +Abe funyy qrngu oent gubh jnaqre’fg va uvf funqr, +Jura va rgreany yvarf gb gv`r gubh tebj’fg: + Fb ybat nf `ra pna oerngur be rlrf pna frr, + Fb ybat yvirf guvf, naq guvf tvirf yvsr gb gurr.