Initial commit, working MelCrypt
This commit is contained in:
parent
1ebc7f567c
commit
408254cf5c
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -22,3 +22,4 @@
|
|||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
/bin/
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MelcryptJavaAPI</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>
|
|
@ -0,0 +1,72 @@
|
|||
package de.Thiesyy.MelcryptJavaAPI.Core;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.Thiesyy.MelcryptJavaAPI.Util.KeyGenerator;
|
||||
import de.Thiesyy.MelcryptJavaAPI.Util.MelcryptDataSet;
|
||||
|
||||
public class Melcrypt {
|
||||
public static MelcryptDataSet encode(int security, String Text) {
|
||||
System.out.println("Encrypting can take large Calculation power!");
|
||||
String[] Keys = new String[security];
|
||||
for(int x = 0; x != security; x++) {
|
||||
Keys[x] = KeyGenerator.generateKey();
|
||||
}
|
||||
for(String x : Keys) {
|
||||
Text = encrypt(x, Text);
|
||||
}
|
||||
return new MelcryptDataSet(Keys, Text);
|
||||
}
|
||||
private static String encrypt(String key, String Text) {
|
||||
int Length = Text.length() * 9;
|
||||
String Rdm = genRdmStr(Length);
|
||||
String toRet = Rdm;
|
||||
long KeyLoc = -1;
|
||||
long Loc = 0;
|
||||
StringBuilder Return = new StringBuilder(Rdm);
|
||||
for(int x = 0; x != Text.length(); x++) {
|
||||
KeyLoc++;
|
||||
Loc += Integer.parseInt(key.charAt((int) (KeyLoc % 8))+"");
|
||||
Return.setCharAt((int) Loc, Text.charAt(x));
|
||||
}
|
||||
toRet = Return.toString();
|
||||
|
||||
return toRet;
|
||||
}
|
||||
|
||||
private static String genRdmStr(int length) {
|
||||
String toUse = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz[]}{?.,=!§$%&()1234567890";
|
||||
String built = "";
|
||||
for(int x = 0; x != length; x++)
|
||||
built += toUse.charAt(new Random().nextInt(toUse.length()));
|
||||
|
||||
return built;
|
||||
}
|
||||
public static String decode(MelcryptDataSet MDS) {
|
||||
String Crypted = MDS.getCrypted();
|
||||
String[] keays = new String[MDS.getCodes().length];
|
||||
int a = keays.length-1;
|
||||
for(String x : MDS.getCodes()) {
|
||||
keays[a] = x;
|
||||
a--;
|
||||
}
|
||||
|
||||
for(String key : keays) {
|
||||
Crypted = decrypt(key, Crypted);
|
||||
}
|
||||
return Crypted;
|
||||
|
||||
}
|
||||
private static String decrypt(String key, String crypted) {
|
||||
String toRet = "";
|
||||
int RealtextLength = crypted.length() / 9;
|
||||
int KeyLoc = -1;
|
||||
int Loc = 0;
|
||||
for(int x = 0; x != RealtextLength; x++) {
|
||||
KeyLoc++;
|
||||
Loc += Integer.parseInt(key.charAt(KeyLoc % 8)+"");
|
||||
toRet += crypted.charAt(Loc);
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package de.Thiesyy.MelcryptJavaAPI.Core;
|
||||
|
||||
import de.Thiesyy.MelcryptJavaAPI.Util.MelcryptDataSet;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
MelcryptDataSet x = Melcrypt.encode(4, "Yalla habibi");
|
||||
System.out.println(x.getCrypted());
|
||||
System.out.println(Melcrypt.decode(x));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package de.Thiesyy.MelcryptJavaAPI.Util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class KeyGenerator {
|
||||
/**
|
||||
* Returns a random Key for the Melcrypt Encryption.
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static String generateKey() {
|
||||
String x = "";
|
||||
for(int y = 0; y != 8; y++) {
|
||||
int z;
|
||||
z = (int) ((new Random().nextInt(10)*4+new SecureRandom().nextInt(10)+System.currentTimeMillis()+new Random().nextInt(10))%10);
|
||||
if(z==0)z=3;
|
||||
x+=z;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package de.Thiesyy.MelcryptJavaAPI.Util;
|
||||
|
||||
public class MelcryptDataSet {
|
||||
private String[] codes;
|
||||
private String Crypted;
|
||||
/**
|
||||
* Returns a random Key for the Melcrypt Encryption.
|
||||
* @param Codes
|
||||
* @param Cryptedtext
|
||||
* @return
|
||||
* Data Set with Codes and Crypted Text
|
||||
*/
|
||||
public MelcryptDataSet(String[] codes, String Crypted) {
|
||||
this.codes = codes;
|
||||
this.Crypted = Crypted;
|
||||
}
|
||||
public String[] getCodes() {
|
||||
return codes;
|
||||
}
|
||||
public void setCodes(String[] codes) {
|
||||
this.codes = codes;
|
||||
}
|
||||
public String getCrypted() {
|
||||
return Crypted;
|
||||
}
|
||||
public void setCrypted(String crypted) {
|
||||
Crypted = crypted;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue