final commit

This commit is contained in:
Akito123321 2024-04-24 21:30:54 +02:00
commit 009fc6cae2
11 changed files with 29450 additions and 0 deletions

10
.classpath Normal file
View File

@ -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-19">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Piegenere</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>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=19
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=19
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.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=19

1363
Resources/Bee.txt Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

6990
Resources/Goethe--Faust.txt Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

21005
Resources/pi_E6.txt Normal file

File diff suppressed because it is too large Load Diff

BIN
bin/main/Main.class Normal file

Binary file not shown.

47
src/main/Main.java Normal file
View File

@ -0,0 +1,47 @@
package main;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class Main {
public static String PIE;
public static void main(String[] args) throws IOException {
PIE = Files.readString(new File("Resources/pi_E6.txt").toPath()).replaceAll("[^0-9]", "");
String text = Files.readString(new File("Resources/Goethe--Faust.txt").toPath()).toUpperCase().replaceAll("[^A-Z]", "");
String[] piegenereKey = new String[] { "SDF", "JA", "HJZR", "M", "HTASBOATC", "NAFARTZQ", "FAFVB", "AF", "QDOP",
"VCXY" };
System.out.println("Orginal: \n" + text);
String encrypted = viegenere(text, createViegenereKey(text.length(), piegenereKey), false);
System.out.println("verschlüsselt: \n" + encrypted);
System.out.println(
"entschlüsselt \n" + viegenere(encrypted, createViegenereKey(text.length(), piegenereKey), true));
Files.writeString(Path.of("Resources/Goethe--FaustEncrypted.txt"), encrypted);
System.out.println(text.length() + "/" + encrypted.length());
}
public static String createViegenereKey(int length, String[] piegenereKey) {
String result = "";
int pos = 0;
while (result.length() < length) {
char current = PIE.charAt(pos++);
result += piegenereKey[Integer.valueOf(current - '0')];
}
return result.substring(0, length);
}
public static String viegenere(String input, String key, boolean decrypt) {
String result = "";
int keypos = 0;
for (int i = 0; i < input.length(); i++) {
result += (char) (decrypt ? (input.charAt(i) - key.charAt(keypos) + 26) % 26 + 'A'
: ((input.charAt(i) - 'A') + key.charAt(keypos) - 'A') % 26 + 'A');
keypos++;
keypos %= key.length();
}
return result;
}
}