Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Date;
- import java.util.HashMap;
- /*
- *
- * This tool encrypts numbers with a given public key and replace similarities in the cipher text with the clear text.
- * This tool only cracks the unmodified RSA algorithm with clear text sizes up to 2147483647 per number.
- * It's only made for scientific purposes, not for criminal ones.
- *
- * @author mitosis
- * @version 1.0
- *
- */
- public class RSAGuess {
- public static void main(String[] args) {
- try {
- String argsadded = "";
- for (int i = 0; i < args.length; i++) {
- argsadded = argsadded + args[i];
- }
- if (argsadded.isEmpty() || argsadded.equalsIgnoreCase("version")) {
- + "\nUse argument 'help' to learn how to use this tool.");
- } else if (argsadded.equalsIgnoreCase("help")) {
- System.out.println("The one and only rule: Use this tool ONLY for GOOD purposes."
- + "\nType the arguments like this: N e s l c d" + "\nN - RSA modulus" + "\ne - public exponent"
- + "\ns - smallest number exptected in message (the number doesn't has to exist in message!)"
- + "\nl - largest number expected in message (the number doesn't has to exist in message!)"
- + "\nc - ciphertext" + "\nd - delimiter" + "\n" + "\nA tip:"
- + "\nMaybe you are a kind of confused what s and l argument mean. Just use 0 for s and the highest number you expect in the message for l."
- + "\nAnother tip:"
- + "\nSome delimiter chars won't work. I never had problems with using a minus -");
- } else {
- BigInteger N = new BigInteger(args[0]);
- BigInteger e = new BigInteger(args[1]);
- String m = "";
- int begin = Integer.parseInt(args[2]);
- int end = Integer.parseInt(args[3]);
- String chr = args[5];
- String c = args[4];
- int g = begin;
- long start = new Date().getTime();
- Dictionary d = new Dictionary();
- HashMap<Integer, BigInteger> cMap = new HashMap<Integer, BigInteger>();
- while (g <= end) {
- BigInteger cipher = new BigInteger(Integer.toString(g)).modPow(e, N);
- d.addEntry(g, cipher);
- g++;
- }
- for (int i = 0; i < c.split(chr).length; i++) {
- cMap.put(i, new BigInteger((c.split(chr)[i])));
- }
- g = 0;
- String dSize = Integer.toString(d.getDictionary().size());
- for (int i = 0; i < cMap.size(); i++) {
- for (BigInteger b = new BigInteger("0"); b.compareTo(new BigInteger(dSize)) == -1; b = b
- .add(new BigInteger("1"))) {
- if (cMap.get(i).toString().equals(d.getDictionary().get(b.intValueExact()).toString())) {
- cMap.put(i, b);
- break;
- }
- }
- }
- for (int i = 0; i < cMap.size(); i++) {
- if (i == cMap.size() - 1) {
- m = m + cMap.get(i).toString();
- } else {
- m = m + cMap.get(i).toString() + chr;
- }
- }
- long runningTime = new Date().getTime() - start;
- BigInteger bits = new BigInteger(Integer.toString(N.toString(2).length() / 2));
- System.out.println("cracked RSA-" + bits + " in " + runningTime + "ms. m=" + m);
- }
- } catch (Throwable e) {
- System.out.println("Something went wrong. Use argument 'help'.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment