Language used: C++

This algorithm code can be used to generate random strings that can be used as Passwords. This code goes through some processes before arriving to the last result. It firsttakes a string then changes it to characters after which each character is randomized then printed out as a array of new combined characters (string/password).

The Breakdown.

I first include this library <bits/stdc++.h>this will enable us to convert the strings into characters using the function strcpy();. We need to convert the string to characters because when we are randomizing the hash or any string we need to go through (iterate) all the characters. Strings are a series of  characters, so we can take the input as a string but later in the program convert it into this array of characters so that we can randomize each of them.

I then included <ctime> this inbuilt library helps in making sure we can use the srand(); and rand(); functions when it comes time to randomize our string.

I then set some of the variable as global variables especially wchar_t Modular; and the reason is when you declare it inside the main function you will actually get different results (very different). wchar_t converts characters to integers for example the wchar_t representation of ‘A’ will be equal to 65 (wchar_t A = 65). The problem is in this scenario when we make the variable  wchar_t Modular; a local variable to the main function we get a very different result, in my case i was getting 32829, which in this case it is very off! What we need to have is the actual representation of the characters into ASCII code. The reason why we need this is to later divide the result with a reasonable number like 1/97 to get a final seed. Now this really matters especially when you have a long string. When represented correctly a string of characters ‘D’,’a’,’v’,’i’,’d‘ will be equal to 488. In which the representation is easy to trace back on how the result was achieved, in this case D+a+v+i+d which is represented by 68+97+118+105+100 = 488. But if we do this while wchar_t Modular; is locally in the main function then the results will be really off and will require a greater number to divide the sum of the characters from the string (which is solvable with large numbers) but on the other hand if the hash/input string is short then you will get most of the results containing ‘imaginary characters’. The result of ‘D’,’a’,’v’,’i’,’d’ if the variable was declared locally would have been 33254. As you can see the result is off.

I then get the length of a hash/input string then assign it to the Modular variable Modular += Hash_Entry[i];which we later divide it Modular/1/97;to get the Final_Seedyou can change the threshold of the dividing number but don’t go too low or two high i find that 1/90 to 1/100 worked really well in this illustration.

I then converted the input string into individual characters, this is achieved by strcpy();which will take two arguments the variable which the characters need to be saved (char Password), and the string input that will provide the characters (Hash_Entry). Here you will encounter something if you make the char Password variable a global variable. If you make it a global variable it will require  you to set a constant integer value of which it can not accept Length+1 while it is a global variable, but it will accept all this if you make it a local variable to the main function.

For more randomization i again divide the random result i  get from the inbuilt random rand();function and divide it by the Final_Seed by doing this the results will not have repetition on a standard hash length string, and will have less same frequency in terms of the result even in a short string like three characters.

Finally i iterate through the new randomized characters and save them and out put them Password[i];

//Random Password Generator from a String Bits
// David Kimolo

/*Include the libraries needed*/

#include <iostream> // for input and output
#include <bits/stdc++.h> // To enable conversion of strings to characters
#include <ctime> // To enable use of the random function using time

using namespace std;

// Global Variables

string Hash_Entry = "9c6a362fceab56f9281acefe8a1596ccaaa36f7f8ffa10fdec697a9629fccc3e"; // Any Hash string or String
wchar_t Modular; // The number we will use to set random seed
int long  Length  = Hash_Entry.length(); // If you want a shorter or longer password you can define it here
int i = 0;

int main ()
    char Password[Length+1];

    for (int i = 0; i<Length; ++i)
        Modular += Hash_Entry[i];

    int Final_Seed = Modular/1/97; // This makes the result more random

    /*Converting The Hash_Entry to Characters
     * then using that to randomize the result*/

    strcpy(Password, Hash_Entry.c_str());

    while (i<Length)
        int Randomizer = rand()%Final_Seed;
        Password[i] = Hash_Entry[Randomizer];


    for (int i = 0; i<Length; ++i) {

        cout << Password[i];
    return 0;
    //End of the Program


You can actually get real hashes of Bitcoin using API’s and then map them to be the string input after you will be getting even more random strings as outputs every single time limiting a chance of ever getting a repetitive password/output. I may do a post on this one just to show you my approach to this.


Github link:

Leave a Reply

Your email address will not be published. Required fields are marked *