Deozaan

BruteForce.cs for BIP-38

Apr 8th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.64 KB | None | 0 0
  1. /* Inspired by:
  2.  * https://www.reddit.com/r/btc/comments/4dkw1q/no_one_cracked_05btc_paperwallet_with_easy/ ( https://archive.is/1y58e )
  3.  *
  4.  * A very inefficient way to generate every possible password meeting the following criteria:
  5.  *
  6.  * 1: Password is 6 characters long
  7.  * 2: Password is made up of ONLY letters from the US alphabet, lower and upper case (a-z and A-Z). No symbols or numbers.
  8.  * 3: If you divide the number of uppercase letters by the number of lower case letters in the password, you get an integer
  9.  *    (assume this means there are 3, 4, or 5 upper-case letters in the password).
  10.  *
  11.  * Then write every 100,000 passwords out to a new file, which can be used to attempt to actually bruteforce the passwords in the file(s) using something like
  12.  * https://github.com/Dirbaio/bip38-cracker ( https://archive.is/OrHRc )
  13.  * Note that BIP-38 intentionally makes it time consuming to attempt passwords, so trying all ~20 billion (52^6) in one go is unrealistic.
  14.  * Hence breaking them up into subsets of 100,000 passwords.
  15.  */
  16.  
  17. using UnityEngine;
  18. using System.Collections;
  19. using System;
  20. using System.Text;
  21. using System.IO;
  22. using System.Runtime.Serialization.Formatters.Binary;
  23.  
  24. // Attach this component to an object in Unity and let it do its thing.
  25. public class BruteForce : MonoBehavior {
  26.     public int startPos1 = 0;
  27.     public int startPos2 = 0;
  28.     public int startPos3 = 0;
  29.     public int startPos4 = 0;
  30.     public int startPos5 = 0;
  31.     public int startPos6 = 0;
  32.  
  33.     public int startFile = 0;
  34.  
  35.     string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  36.  
  37.     string outputFile = "bf.txt";
  38.  
  39.     void Start() {
  40.         if (!File.Exists(outputFile)) {
  41.             File.Create(outputFile);
  42.         }
  43.  
  44.         StartCoroutine(GenerateFile());
  45.     }
  46.  
  47.     IEnumerator GenerateFile() {
  48.         yield return new WaitForSeconds(0.25f);
  49.  
  50.         StringBuilder result = new StringBuilder();
  51.         int linesAdded = 0;
  52.         int filesWritten = startFile;
  53.  
  54.         float timer = Time.realtimeSinceStartup;
  55.  
  56.         #region sanity checking
  57.  
  58.         if (startPos6 >= 52) {
  59.             startPos6 = 0;
  60.             startPos5++;
  61.         }
  62.  
  63.         if (startPos5 >= 52) {
  64.             startPos5 = 0;
  65.             startPos4++;
  66.         }
  67.  
  68.         if (startPos4 >= 52) {
  69.             startPos4 = 0;
  70.             startPos3++;
  71.         }
  72.  
  73.         if (startPos3 >= 52) {
  74.             startPos3 = 0;
  75.             startPos2++;
  76.         }
  77.  
  78.         if (startPos2 >= 52) {
  79.             startPos2 = 0;
  80.             startPos1++;
  81.         }
  82.  
  83.         #endregion //sanity checking
  84.  
  85.         int chr1 = startPos1;
  86.         int chr2 = startPos2;
  87.         int chr3 = startPos3;
  88.         int chr4 = startPos4;
  89.         int chr5 = startPos5;
  90.         int chr6 = startPos6;
  91.  
  92.         Debug.Log("Starting at positions: " + chr1 + " " + chr2 + " " + chr3 + " " + chr4 + " " + chr5 + " " + chr6 +
  93.             " Chars length is: " + chars.Length);
  94.         yield return 0;
  95.  
  96.         for (chr1 = startPos1; chr1 < chars.Length; chr1++) {
  97.             startPos1 = 0;
  98.  
  99.             for (chr2 = startPos2; chr2 < chars.Length; chr2++) {
  100.                 startPos2 = 0;
  101.  
  102.                 for (chr3 = startPos3; chr3 < chars.Length; chr3++) {
  103.                     startPos3 = 0;
  104.  
  105.                     for (chr4 = startPos4; chr4 < chars.Length; chr4++) {
  106.                         startPos4 = 0;
  107.  
  108.                         for (chr5 = startPos5; chr5 < chars.Length; chr5++) {
  109.                             startPos5 = 0;
  110.  
  111.                             for (chr6 = startPos6; chr6 < chars.Length; chr6++) {
  112.                                 startPos6 = 0;
  113.  
  114.                                 if (PwdMeetsCriteria(chr1, chr2, chr3, chr4, chr5, chr6)) {
  115.                                     string pwd = chars.Substring(chr1, 1) + chars.Substring(chr2, 1) + chars.Substring(chr3, 1) + chars.Substring(chr4, 1) + chars.Substring(chr5, 1) + chars.Substring(chr6, 1);
  116.                                     result.AppendLine(pwd);
  117.                                     linesAdded++;
  118.  
  119.                                     if (linesAdded >= 100000) {
  120.                                         File.AppendAllText(String.Format("bf/bf{0:D6}.txt", filesWritten), result.ToString(), new System.Text.UTF8Encoding());
  121.                                         filesWritten++;
  122.                                         Debug.LogWarning("Writing out file #" + filesWritten.ToString("N0") +
  123.                                             ".\nCurrently done with: " + chr1 + " " + chr2 + " " + chr3 + " " + chr4 + " " + chr5 + " " + (chr6 + 1));
  124.                                         // reset these things back to the beginning
  125.                                         linesAdded = 0;
  126.                                         result = new StringBuilder();
  127.                                         //yield return 0;
  128.                                     }
  129.                                 } else {
  130.                                     chr6 = (chr6 == 0) ? 25 : 51;
  131.                                 }
  132.  
  133.                                 if (Time.realtimeSinceStartup > (timer + 1)) {
  134.                                     //Debug.Log("RealTime Since Startup: " + Time.realtimeSinceStartup);
  135.                                     // reset timer and display progress
  136.                                     timer = Time.realtimeSinceStartup;
  137.                                     Debug.Log("Progress: " + ((UInt64)(((UInt64)chr1 * 52L * 52L * 52L * 52L * 52L) + ((UInt64)chr2 * 52L * 52L * 52L * 52L) + ((UInt64)chr3 * 52L * 52L * 52L) + ((UInt64)chr4 * 52L * 52L) + ((UInt64)chr5 * 52L) + ((UInt64)chr6))).ToString("N0") +
  138.                                         " of 19,763,298,048" +
  139.                                         ".\nLines added: " + linesAdded.ToString("N0") +
  140.                                         ".\nCurrently done with: " + chr1 + " " + chr2 + " " + chr3 + " " + chr4 + " " + chr5 + " " + (chr6 + 1));
  141.                                     yield return 0;
  142.                                 }
  143.                             }
  144.                         }
  145.                     }
  146.                 }
  147.             }
  148.         }
  149.  
  150.         if (linesAdded > 0) {
  151.             File.AppendAllText(String.Format("bf/bf{0:D6}.txt", filesWritten), result.ToString(), new System.Text.UTF8Encoding());
  152.             filesWritten++;
  153.         }
  154.  
  155.         Debug.Log("FINISHED! Currently done with: " + chr1 + " " + chr2 + " " + chr3 + " " + chr4 + " " + chr5 + " " + chr6);
  156.     }
  157.  
  158.     bool PwdMeetsCriteria(int chr1, int chr2, int chr3, int chr4, int chr5, int chr6) {
  159.         int lower = 0;
  160.         int upper = 0;
  161.  
  162.         if (chr1 < 26) { lower++; } else { upper++; }
  163.         if (chr2 < 26) { lower++; } else { upper++; }
  164.         if (chr3 < 26) { lower++; } else { upper++; }
  165.         if (chr4 < 26) { lower++; } else { upper++; }
  166.         if (chr5 < 26) { lower++; } else { upper++; }
  167.         if (chr6 < 26) { lower++; } else { upper++; }
  168.  
  169.         if (upper == 3 || upper == 4 || upper == 5) {
  170.             return true;
  171.         } else {
  172.             return false;
  173.         }
  174.     }
  175. }
Add Comment
Please, Sign In to add comment