Skip to content

Commit

Permalink
adfgx
Browse files Browse the repository at this point in the history
  • Loading branch information
FLCN17 committed May 30, 2018
1 parent 37e1fe8 commit 0f3cdfe
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 1,022 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.metadata/
/.recommenders/
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions ADFGVXCipher/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions ADFGVXCipher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions ADFGVXCipher/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ADFGVXCipher</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions ADFGVXCipher/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=10
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=10
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=10
36 changes: 36 additions & 0 deletions ADFGVXCipher/ENCRYPTCHART.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
z,
y,
n,
q,
t,
9,
5,
r,
x,
e,
g,
l,
f,
p,
4,
h,
1,
b,
j,
c,
6,
7,
d,
m,
s,
v,
u,
o,
2,
3,
a,
i,
k,
w,
8,
0
90 changes: 90 additions & 0 deletions ADFGVXCipher/src/ADFGVXCipher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class ADFGVXCipher {

public static void main(String[] args) throws IOException {
int menuSelect;
Chart codeChart = null;
Scanner keyboard = new Scanner(System.in);
PrintWriter chartFile = new PrintWriter("ENCRYPTCHART.txt");
String codeDigits = "", message, phrase, cipherText = "", newChart = "", chartFileLoc;
boolean validInput = false;
//encryption or decryption
do {
System.out.println("Would you like to\n1. Encrypt\n2. Decrypt\nPlease select option: ");
menuSelect = keyboard.nextInt(); keyboard.nextLine();
} while(menuSelect != 1 && menuSelect != 2);
//old chart or new chart?
do {
System.out.println("Are you creating a new chart?\n(Y/N): ");
newChart = keyboard.nextLine();
if(newChart.toLowerCase().equals("y") || newChart.toLowerCase().equals("n"))
validInput = true;
} while(!validInput);
do {
System.out.println("Please enter the enciphering digits.\ne.g. ADFGX(5) or ADFGVX(6)\n");
codeDigits = keyboard.nextLine();
} while(codeDigits.length() < 5 || codeDigits.length() > 6);
if(newChart.equals("y")) {
//make new chart
codeChart = new Chart(codeDigits);
codeChart.ChartPrint(chartFile);
chartFile.close();
}
else {
//get location of chart file, throw into constructor
System.out.println("Please enter the path to chart file \n(If in root folder, just name without file extension)\n");
chartFileLoc = keyboard.nextLine(); chartFileLoc += ".txt";
//load chart from file, line by line
}
//save new chart to file to export

//get message
System.out.println("Please enter message: "); message = keyboard.nextLine();
System.out.println("Please the encryption phrase: "); phrase = keyboard.nextLine();

switch(menuSelect) {
case 1: //encrypt
cipherText = Encryption(message, phrase, codeChart);
break;
case 2: //decrypt
break;
}

//System.out.print(codeDigits.charAt(0) == 65);
System.out.printf("%s", cipherText);

keyboard.close();
}

public static String Encryption(String clearText, String secretPhrase, Chart codeChart) {
String cipherText = "", sortedPhrase = "";
//strip whitespace
clearText.replace(" ", "");
//get Cartesian coords
for(int i = 0; i < clearText.length(); i++)
cipherText += codeChart.CodeReturn(clearText.toLowerCase().charAt(i));
//perform phrase sorting



return cipherText;
}

public static String Decryption(String cipherText, Chart codeChart) {
String plainText = "";


return plainText;
}

private static String sortingMethod(String secretPhrase) {
String sortedPhrase = "";
//sort - .toCharArray()

return sortedPhrase;
}

}
52 changes: 52 additions & 0 deletions ADFGVXCipher/src/Chart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class Chart {
private int keySpace;
private ArrayList<String> alphabet = new ArrayList<>(Arrays.asList("a","b","c","d","e","f","g","h","i","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","j","1","2","3","4","5","6","7","8","9","0"));
private String[] chart;
private Random rand = new Random();
private String codeDigits;

public Chart(String codeDigits) {
this.codeDigits = codeDigits;
this.keySpace = this.codeDigits.length()*this.codeDigits.length();
this.chart = ChartMaker();
}

public Chart(String codeDigits, String[] givenChart) {
this.codeDigits = codeDigits;
this.chart = givenChart;
this.keySpace = (givenChart.length > 25 ? 36 : 25);
}

private String[] ChartMaker() {
int spot;
chart = new String[this.keySpace];
for(;this.keySpace < alphabet.size();)
alphabet.remove(this.keySpace);

//fill chart with letters
for(int i = 0; i < chart.length; i++) {
spot = rand.nextInt(alphabet.size());
chart[i] = alphabet.get(spot);
alphabet.remove(spot);
}
return chart;
}

public void ChartPrint(PrintWriter outputFile) {
for(int i = 0; i < chart.length; i++)
outputFile.printf("%s%s", chart[i], (i == chart.length-1? "" : ",\n"));
}

public String CodeReturn(char letter) {
String returnCode = "";
for(int i = 0; i < this.keySpace; i++)
if(letter == chart[i].charAt(0))
returnCode = codeDigits.charAt(i%codeDigits.length()) + "" + codeDigits.charAt(i/codeDigits.length());
return returnCode;
}
}

0 comments on commit 0f3cdfe

Please sign in to comment.