Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. package freenet.tools;
  2.  
  3. import static freenet.keys.InsertableClientSSK.createRandom;
  4. import static java.lang.String.format;
  5. import static java.lang.System.currentTimeMillis;
  6. import static java.util.concurrent.TimeUnit.MILLISECONDS;
  7.  
  8. import freenet.crypt.RandomSource;
  9. import freenet.crypt.Yarrow;
  10. import freenet.keys.InsertableClientSSK;
  11.  
  12. /**
  13.  * Generates a vanity key pair, i.e. a keypair with the public key starting
  14.  * with a specific set of characters.
  15.  *
  16.  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  17.  */
  18. public class GenerateVanityKey {
  19.  
  20.     public static void main(String... arguments) throws Exception {
  21.         RandomSource randomSource = new Yarrow();
  22.         long firstOutput = currentTimeMillis();
  23.         long lastOutput = firstOutput;
  24.         long generatedKeys = 0;
  25.         long foundKeys = 0;
  26.         String prefixToSearch = (arguments.length > 0) ? arguments[0].toLowerCase() : "free";
  27.         while (true) {
  28.             InsertableClientSSK clientSSK = createRandom(randomSource, "");
  29.             generatedKeys++;
  30.             if (clientSSK.getURI().toString().toLowerCase().substring(4).startsWith(prefixToSearch)) {
  31.                 System.err.println(format("\r%s <- %s", clientSSK.getURI(),
  32.                         clientSSK.getInsertURI()));
  33.                 foundKeys++;
  34.             }
  35.             long currentTime = currentTimeMillis();
  36.             if ((currentTime - lastOutput) > 1000) {
  37.                 long timeSpent = currentTime - firstOutput;
  38.                 System.out.print(format("\r%d/s, %.3f/s",
  39.                         generatedKeys / MILLISECONDS.toSeconds(timeSpent),
  40.                         (double) foundKeys / MILLISECONDS.toSeconds(timeSpent)));
  41.                 lastOutput = currentTime;
  42.             }
  43.         }
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement