Advertisement
Guest User

Solve Aman's Challenge

a guest
Oct 23rd, 2017
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. // AMANIDFBruteforce.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7.  
  8. int hashFunc(std::string str);
  9.  
  10. int main()
  11. {
  12.     std::string charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  13.     bool found = false;
  14.     if (hashFunc("i7NU") == 3183413) {
  15.         std::cout << "function working fine" << std::endl;
  16.     }
  17.     else {
  18.         std::cout << "function not working" << std::endl;
  19.         return 0;
  20.     }
  21.  
  22.  
  23.     // solve first one
  24.     for (int i = 0; i < charset.length() && !found; i++) {
  25.         for (int j = 0; j < charset.length() && !found; j++) {
  26.             for (int k = 0; k < charset.length() && !found; k++) {
  27.                 std::string test = "i";
  28.                 test += charset[i];
  29.                 test += charset[j];
  30.                 test += charset[k];
  31.                 // std::cout << "testing " << test << std::endl;
  32.                 if (hashFunc(test) == 3183413) {
  33.                     std::cout << "found " << test <<  std::endl;
  34.                     found = true;
  35.                 }
  36.             }
  37.         }
  38.     }
  39.  
  40.     found = false;
  41.  
  42.     // solve second one
  43.     for (int i = 0; i < charset.length() && !found; i++) {
  44.         for (int j = 0; j < charset.length() && !found; j++) {
  45.             for (int k = 0; k < charset.length() && !found; k++) {
  46.                 for (int m = 0; m < charset.length() && !found; m++) {
  47.                     std::string test = "i";
  48.                     test += charset[i];
  49.                     test += charset[j];
  50.                     test += charset[k];
  51.                     test += charset[m];
  52.                     // std::cout << "testing " << test << std::endl;
  53.                     if (hashFunc(test) == 98509926) {
  54.                         std::cout << "found " << test << std::endl;
  55.                         found = true;
  56.                     }
  57.                 }
  58.                
  59.             }
  60.         }
  61.     }
  62.  
  63.     found = false;
  64.  
  65.     // solve third one
  66.     for (int i = 0; i < charset.length() && !found; i++) {
  67.         for (int j = 0; j < charset.length() && !found; j++) {
  68.             for (int k = 0; k < charset.length() && !found; k++) {
  69.                 std::string test = "i";
  70.                 test += charset[i];
  71.                 test += charset[j];
  72.                 test += charset[k];
  73.                 // std::cout << "testing " << test << std::endl;
  74.                 if (hashFunc(test) == 3179658) {
  75.                     std::cout << "found " << test << std::endl;
  76.                     found = true;
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. int hashFunc(std::string str) {
  84.     int hash = 0;
  85.     if (str.length() == 0)return hash;
  86.     for (int i = 0; i < str.length(); i++)
  87.     {
  88.         char c = str.c_str()[i];
  89.         hash = ((hash << 5) - hash) + c;
  90.         hash |= 0;
  91.     }
  92.  
  93.     return hash;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement