1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <string>
using namespace std;
void scrambleString(string str)
{
int x = str.length();
for (int y = x; y > 0; y--)
{
int pos = rand() % x;
char tmp = str[y - 1];
str[y - 1] = str[pos];
str[pos] = tmp;
}
cout << str;
}
int main()
{
// Arrays for RNG to work with //
char letters[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
char symbols[] = { '!', '£', '$', '%', '&', '*', '@', '~' };
char numbers[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
// Other Variables //
int letterIn;
int specialIn;
int numberIn;
string randomPass;
string holdString;
cout << "No of Letters: ";
cin >> letterIn;
cout << "No of Special char: ";
cin >> specialIn;
cout << "No of Numbers: ";
cin >> numberIn;
// Letters
for (int i = 0; i < letterIn; i++)
{
int RNG = rand() % 26;
char holdChar = letters[RNG];
// Convert to String
holdString.insert(i, 1, holdChar);
}
// Symbols
for (int i = 0; i < specialIn; i++)
{
int RNG = rand() % 8;
char holdChar = symbols[RNG];
// Convert to String
holdString.insert(letterIn, 1, holdChar);
}
// Numbers
for (int i = 0; i < numberIn; i++)
{
int RNG = rand() % 8;
char holdChar = symbols[RNG];
// Convert to String
holdString.insert(letterIn+specialIn, 1, holdChar);
}
cout << holdString << endl;
scrambleString(holdString);
}
|