This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd26763
commit 91e40b6
Showing
30 changed files
with
179 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Gawayne stood confounded, the blood rushed into his face, and he shrank within himself for very shame. "Cursed," he cried, "be cowardice and covetousness both; in you are villany and vice, that virtue destroy." Then he takes off the girdle and throws it to the knight in green, cursing his cowardice and covetousness. The Green Knight, laughing, thus spoke: "Thou hast confessed so clean, and acknowledged thy faults, that I hold thee as pure as thou hadst never forfeited since thou wast first born. I give thee, sir, the gold-hemmed girdle as a token of thy adventure at the Green Chapel. Come now to my castle, and we shall enjoy together the festivities of the New Year" (ll. 2340-2406). | ||
"Nay, forsooth," quoth the knight, "but for your kindness may God requite you. Commend me to that courteous one your comely wife, who with her crafts has beguiled me. But it is no uncommon thing for a man to come to sorrow through women's wiles; for so was Adam beguiled with one, and Solomon with many. Samson was destroyed by Delilah, and David suffered much through Bathsheba. 'It were indeed great bliss for a man to love them well and believe them not.' Since the greatest upon earth were so beguiled, methinks I should be excused. But God reward you for your girdle, which I will ever wear in remembrance of my fault, and when pride shall exalt me, a look to this love-lace shall lessen it (ll. 2407-2438). But since ye are the lord of yonder land, from whom I have received so much honour, tell me truly your right name, and I shall ask no more questions." |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dataanalysis; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Runs DataAnalysis without arguments, taking contents of every input file and feeding this to | ||
* DataFileWriter, which in return feeds the content to DataAnalysis | ||
* Used for populating all data, takes ~20 seconds to run and collects 5000 data points | ||
*/ | ||
public class DataPopulater { | ||
public static void main(String[] args) throws InterruptedException { | ||
File inputFolder = new File("data/inputs"); | ||
File[] allInputs = inputFolder.listFiles(); | ||
|
||
for (int i = 0; i < allInputs.length; i++) { | ||
System.out.printf("Collecting data on %s...%-20s", allInputs[i].getName(), ' '); | ||
|
||
String fileNameWithoutExtension = allInputs[i].getName().substring(0, | ||
allInputs[i].getName().lastIndexOf(".")); | ||
DataFileReader.main(fileNameWithoutExtension); | ||
|
||
System.out.print("\rData collection complete. Moving to next file...\n"); | ||
} | ||
System.out.print("\rData population complete"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dataanalysis; | ||
|
||
public class DataVisualizer { | ||
public DataVisualizer() { | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
new DataVisualizer(); | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/java/frequencyanalysissimulator/business/CosetManager.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/main/java/frequencyanalysissimulator/business/KeyLengthMethod.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ncyanalysissimulator/business/Cipher.java → ...uencyanalysissimulator/crypto/Cipher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/frequencyanalysissimulator/crypto/CosetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package frequencyanalysissimulator.crypto; | ||
|
||
public class CosetManager { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...simulator/business/FrequencyAnalysis.java → ...issimulator/crypto/FrequencyAnalysis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/frequencyanalysissimulator/crypto/KeyLengthMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package frequencyanalysissimulator.crypto; | ||
|
||
public enum KeyLengthMethod { | ||
KASISKI, KERCKHOFF, FRIEDMAN | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/frequencyanalysissimulator/crypto/SimpleSubstitutionCipher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package frequencyanalysissimulator.crypto; | ||
|
||
/** | ||
* Monoalphabetic substitution cipher | ||
* | ||
* @author Varun Singh on 2/20/2023 | ||
*/ | ||
public class SimpleSubstitutionCipher implements Cipher { | ||
private String ciphertext; | ||
private double[] frequencies; | ||
|
||
@Override | ||
public String decrypt() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Decrypts an individual Caesar cipher using Chi Square analysis | ||
* to find which number of shifts matches the standard English frequency | ||
* distribution the most | ||
* | ||
* @time O(n) - Increases linearly with the length of the ciphertext | ||
* | ||
* @param ciphertext | ||
* The cipher text to get the letter rotation of | ||
* @return The letter that represents the number of rotations for the Caesar | ||
* cipher and part of the key for the Vigenere cipher | ||
*/ | ||
private double calculateChiSquare() { | ||
// Populate ciphertext letter frequencies by adding one for every occurrence of | ||
// letter O(n) | ||
for (int i = 0; i < ciphertext.length(); i++) { | ||
char letter = ciphertext.charAt(i); | ||
int asNum = letter - 65; | ||
// Ignore anything other than letters (such as spaces) | ||
if (Character.isAlphabetic((int) letter)) { | ||
frequencies[asNum] += 1.0 / ciphertext.length(); | ||
} | ||
} | ||
|
||
double chiSquareValue = 0; | ||
for (int i = 0; i < 26; i++) { | ||
double standardFrequency = FrequencyAnalysis.standardEnglishFrequencies[i]; | ||
double shiftedCiphertextFrequency = frequencies[i % 26]; | ||
chiSquareValue += Math.pow(shiftedCiphertextFrequency - standardFrequency, 2) / standardFrequency; | ||
} | ||
|
||
return chiSquareValue; | ||
} | ||
|
||
} |
Oops, something went wrong.