Skip to main content
Code Review

Return to Question

added 12 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Java - Custom Encryptionencryption

I made a custom Encryption Libraryencryption library/Classclass which allows to en-/decrypt StringsStrings with a custom charset. I think you'll get what I mean with that when you take a look at the Codecode.

Since I haven't much Crypt-Knowledgecryptography knowledge, I'ldI'd like to ask if someone who knows about it could tell me if this is "safe". I know nothing is 100% safe, but I'ldI'd like to know how far it is safe and maybe some improvements.

Currently I currently have two Programsprograms on a Serverserver running, which are trying to brute-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

PreCrypt.javaPreCrypt.java

Java - Custom Encryption

I made a custom Encryption Library/Class which allows to en-/decrypt Strings with custom charset. I think you'll get what I mean with that when you take a look at the Code.

Since I haven't much Crypt-Knowledge, I'ld like to ask if someone who knows about it could tell me if this is "safe". I know nothing is 100% safe, but I'ld like to know how far it is safe and maybe some improvements.

Currently I have two Programs on a Server running which are trying to brute-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

PreCrypt.java

Custom encryption

I made a custom encryption library/class which allows to en-/decrypt Strings with a custom charset. I think you'll get what I mean with that when you take a look at the code.

Since I haven't much cryptography knowledge, I'd like to ask if someone who knows about it could tell me if this is "safe". I know nothing is 100% safe, but I'd like to know how far it is safe and maybe some improvements.

I currently have two programs on a server running, which are trying to brute-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

PreCrypt.java

deleted 42 characters in body
Source Link
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96

Currently I have two Programs on a Server running which are trying to brutalbrute-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

Thanks in advance

  • PreFiX / Dominik

Currently I have two Programs on a Server running which are trying to brutal-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

Thanks in advance

  • PreFiX / Dominik

Currently I have two Programs on a Server running which are trying to brute-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

Source Link

Java - Custom Encryption

I made a custom Encryption Library/Class which allows to en-/decrypt Strings with custom charset. I think you'll get what I mean with that when you take a look at the Code.

Since I haven't much Crypt-Knowledge, I'ld like to ask if someone who knows about it could tell me if this is "safe". I know nothing is 100% safe, but I'ld like to know how far it is safe and maybe some improvements.

Currently I have two Programs on a Server running which are trying to brutal-force it. After nearly 2 months now, there is nothing found yet, so I guess it's working at least a bit.

PreCrypt.java

package net.prefixaut.prelib.crypt;
import java.security.SecureRandom;
import java.util.List;
import java.util.ArrayList;
import java.math.BigInteger;
public class PreCrypt {
 
 // Remove Constructor
 private PreCrypt() {}
 
 /**
 * Default Charset which contains only default Characters.<br/>
 * Supports: a-z, A-Z, 0-9 and most special-characters. <b>Current amount of supported Characters: 92</b>
 */
 public static final String defaultCharset = "abcdefghijklmopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ#?!\\§$%&/{[(=+-~*_.:,;μ@€<>|)]}";
 /**
 * Complete Charset which contains most relevant Characters<br/>
 * <b>Current amount of supported Characters: 102</b>
 */
 public static final String completeCharset = defaultCharset + "\n\t\r" + // Extra Space Chars
 "üäöÜÄÖ"; // German Extra Chars
 
 public static char countUp(char c, int amount) {
 return PreCrypt.countUp(c, amount, defaultCharset);
 }
 
 public static char countUp(char c, int amount, String str) {
 return PreCrypt.countUp(c, amount, str.toCharArray());
 }
 
 public static char countUp(char c, int amount, char[] charset) {
 boolean set = false;
 for (int i = 0; i < amount; i++) {
 for (int o = 0; o < charset.length; o++) {
 if (c == charset[o]) {
 if (o + 1 >= charset.length) o = 0;
 else o++;
 c = charset[o];
 set = true;
 break;
 }
 }
 if (!set) c++;
 else set = false;
 }
 return c;
 }
 
 public static char countDown(char c, int amount) {
 return PreCrypt.countDown(c, amount, defaultCharset);
 }
 
 public static char countDown(char c, int amount, String str) {
 return PreCrypt.countDown(c, amount, str.toCharArray());
 }
 
 public static char countDown(char c, int amount, char[] charset) {
 boolean set = false;
 for (int i = 0; i < amount; i++) {
 for (int o = 0; o < charset.length; o++) {
 if (c == charset[o]) {
 if (o - 1 < 0) o = charset.length - 1;
 else o--;
 c = charset[o];
 set = true;
 break;
 }
 }
 if (!set) c--;
 else set = false;
 }
 return c;
 }
 
 public static String encrypt(String code, String key) {
 return PreCrypt.encrypt(code, key, PreCrypt.defaultCharset);
 }
 
 public static String encrypt(String code, String key, String charset) {
 return PreCrypt.encrypt(code, key, charset.toCharArray());
 }
 
 public static String encrypt(String code, String key, char[] charset) {
 String r = "";
 r = PreCrypt.count(code, key, charset, (boolean foo, int number, char c) -> {
 if (foo) c = PreCrypt.countUp(c, number, charset);
 else c = PreCrypt.countDown(c, number, charset);
 return c;
 });
 return r;
 }
 
 public static String decrypt(String code, String key) {
 return PreCrypt.decrypt(code, key, PreCrypt.defaultCharset);
 }
 
 public static String decrypt(String code, String key, String charset) {
 return PreCrypt.decrypt(code, key, charset.toCharArray());
 }
 
 public static String decrypt(String code, String key, char[] charset) {
 String r = "";
 r = PreCrypt.count(code, key, charset, (boolean foo, int number, char c) -> {
 if (foo) c = PreCrypt.countDown(c, number, charset);
 else c = PreCrypt.countUp(c, number, charset);
 return c;
 });
 return r;
 }
 
 @FunctionalInterface
 private interface Handler {
 
 public char onCode(boolean foo, int number, char c);
 }
 
 private static String count(String code, String key, char[] charset, Handler handler) {
 String r = "";
 List<Integer> keys = new ArrayList<Integer>();
 BigInteger keySum = new BigInteger(new byte[] { 0 });
 // Load all Key-Values into KEYS, and summarize them in KEYSUM
 for (int i = 0; i < key.length(); i++) {
 int v = (int) key.charAt(i);
 keys.add(v);
 keySum = keySum.add(new BigInteger("" + v));
 }
 List<Integer> temp = new ArrayList<Integer>();
 for (int i = 0; i < code.length(); i++) {
 char c = code.charAt(i);
 int kIndex = i;
 // Get current Index
 while (kIndex > keys.size() - 1)
 kIndex -= keys.size() - 1;
 // Load from Index till end, and from 0 till Index into TEMP
 for (int o = kIndex; o < keys.size(); o++)
 temp.add(keys.get(o));
 for (int o = 0; o < kIndex; o++)
 temp.add(keys.get(o));
 // Encode
 for (int o = 0; o < temp.size(); o++) {
 int count = (temp.get(o) * (o + 1)) / (keySum.intValue() / key.length()) + keySum.intValue();
 count = count >> o + 1;
 c = handler.onCode( (temp.get(o) * (o + 1)) % 2 == 0, count, c);
 }
 r += c;
 temp.clear();
 }
 return r;
 }
 
 /**
 * Generates a Random String with the length of length, from the {@link PreCrypt#defaultCharset default-Charset}
 * 
 * @param length
 * Length of the random String
 */
 public static String generateRandomString(int length) {
 return PreCrypt.generateRandomString(length, PreCrypt.defaultCharset);
 }
 
 /**
 * Generates a Random String with the length of the given length, from the given charset
 * 
 * @param length
 * Length of the random String
 * @param charset
 * Charset which contains all Characters which are allowed for the random String
 */
 public static String generateRandomString(int length, CharSequence charset) {
 return PreCrypt.generateRandomString(length, (String) charset);
 }
 
 /**
 * Generates a Random String with the length of the given length, from the given charset
 * 
 * @param length
 * Length of the random String
 * @param charset
 * Charset which contains all Characters which are allowed for the random String
 */
 public static String generateRandomString(int length, String charset) {
 return PreCrypt.generateRandomString(length, charset.toCharArray());
 }
 
 /**
 * Generates a Random String with the length of the given length, from the given charset
 * 
 * @param length
 * Length of the random String
 * @param charset
 * Charset which contains all Characters which are allowed for the random String
 */
 public static String generateRandomString(int length, char[] charset) {
 String re = "";
 SecureRandom r = new SecureRandom();
 for (int i = 0; i < length; i++)
 re += charset[ (r.nextInt(charset.length))];
 return re;
 }
}

Thanks in advance

  • PreFiX / Dominik
lang-java

AltStyle によって変換されたページ (->オリジナル) /