# Thread: Help with making uppercase words (C++)

1. ## Help with making uppercase words (C++)

I'm working on a program that takes in a word, say 'test'. Then it will output every combination of lowercase and uppercase letters it can out of that word. For example, using 'test', we can make all of these:

test

Test
tEst
teSt
tesT

TEst
TeSt
TesT
tESt
tEsT
teST

TeST
TEsT
TESt
tEST

TEST

The amount of possible words you can make is 2 (1 for uppercase and 1 for lowercase of each letter) to the power of the words size. Since 'test' is 4 characters long, its 2^4, which is 16, if it was a word like 'other', it would be 2^5, which is 32, etc...

The problem I am having is that I can't rattle my brain around a solution to doing this for any word entered. If anyone has any ideas, that'd be awesome.

Edit:

One way would be to make an integer for each letter in the word. This is going to be hard to explain so bear with me...
So with 'test', we have 4 characters, that means 4 variables.

The first variable will help us create single-uppercased letters, like so (each color is a different variable):
Test
tEst
teSt
tesT

You see how it just moves on down the word...
Now let me show you it with two uppercased letters:

TEst
TeSt
TesT
tESt
tEsT
teST

Now here you can see that each variable, green and red, moves along the word.
When a variable reaches the end, the variable before it moves down 1, and the variable that reached the end goes to the character after that variable. So in our example, when green reached the end, the red variable went from 'T' to 'E', and the green variable went to 'S'. Then when the green variable reached the end again, the red went to 'S', and the green went to the variable after the red one, which was 'T'. When all the variables have moved all the way forward, it's done.

Here are 3 uppercased letters:

TESt
TEsT
TeST
tEST

In that example, when the pink variable reached the end, the variable before it moved forward, which was the green one. The rule is basically, when a variable has reached the end, the variable (if any) before it moves forward 1 character, but if that character is at the end, the character before that moves forward 1 character, etc... Until all variables have reached the end.

And lastly, 4 uppercased letters:

TEST

Since all of the characters are already at the end, that is the only possible output.

Soooo, what this is saying, is that when given a word, the program will need to create X amount of variables, where X is the length of the word, then keep moving each variable forward until it either hits the end of the word, or it hits another variable. If all variables are either at the end of the word, or have hit another variable, there are no more combinations for that amount of upper-cased characters, then it will add 1 more variable to the mix to create 2, or 3, etc. upper-cased letters in the word.

So if anyone can tell me how to make integers on-the-fly in C++ that'd be great............................................. .....

More Edits:

Woo, 2 edits in 10 minutes!

Anyway, seeing as how creating a butt load of variables on the fly then just destroying them would take a lot of cpu power, I was thinking of making a vector array, and just change the vector's size to the size of the word (since vectors were made to be easily resizable), then using the above rules to iterate through the array.

Also, if I' not just talking to myself, even though it's 3:53 AM, somebody tell me I'm not crazy .

Another More Edits:

I was also thinking of making a class for each character that holds its postion in the word, if it's uppercase or not, and any other info I can think of. Also, making classes would be helpful, because if a word had special characters or numbers, you can't make them uppercase... so I could only make classes for letters, then iterate through each class.

Keeping You Updated:

For now, unless there is a faster way, I'm using a vector of integers as each variable, and I've made up some basic rules of 'collision':

- if variable is at the end of the word, and it's not the only variable, move the character before it down one, and go to the character after that variable
- if variable has hit another variable, and it's the last variable, then there are no more combinations
- if variable has hit another variable, and it's not the last variable, then the variable before it moves down 1 and the variable that collided moves to the character after that variable

- after checking everything, if word is still valid, move the farthest down variable over 1

Oh and by the way by 'down', I mean down the word:

<- up down ->
THISISALONGWORD

Pseudo Code:

Alright, this is my last post for tonight because now it's 5:22 AM and I'm getting up at 7:00 AM -.-

Anyway, I've thrown together some pseudo-code for the program since winging it didn't really work...

Code:
```while the user wants to continue

If file isn't open
Tell them it wasn't open
else if file is open
break from the loop

While not end of the file
if word has no alpha characters in it
output word
else
make word all lower case
get word size
calculate for the possible combinations (2^word size)

for each amount of letters in the word (1-wordsize)
erase var vector and valid vector
for each alpha character in the word
push back each alpha character's location to var and valid
var size = vecsize

while word is still valid

reset word to lowercase
for each vector in var, make those position's characters upper case
output word to newfile/console
if variable has hit the end of the word or another variable, and is the last variable
word is no longer valid
else if variable has hit the end of the word, and is not the last variable
the variable before it goes down one, and the current variable goes 1 before that```

2. im afraid i dont really see the point of this program, it seems to me that you are bruteforcing using lowercase letters and then changing each word to incorporate all uppercase letters ie

you might as well just tell your bruteforcer to use upper and lower case charset!

3. Try googling something like "c++ all combination in two series"

Where your series are "test" and "TEST" (or pseudo code'ishly "lower(word) and upper(word)")

Here are a few things I came across which might help you:
http://rg03.wordpress.com/2007/04/17...utations-in-c/
http://www.codeguru.com/forum/archiv.../t-326694.html

Edit:
I also just came across this python code in another active thread, it might give you some ideas:
http://forums.remote-exploit.org/sho...61&postcount=3
(Though it doesn't seem quite as clean as some of the C++ I found while googling)

4. Originally Posted by calypso
im afraid i dont really see the point of this program, it seems to me that you are bruteforcing using lowercase letters and then changing each word to incorporate all uppercase letters ie

you might as well just tell your bruteforcer to use upper and lower case charset!
It's not brute forcing that's the problem. It's the word lists. This is so that instead of just testing the word 'dog', it will test 'Dog', 'doG', etc...

It makes a more thorough attack, and decreases the overall size of your word list too.

5. Originally Posted by thorin
Try googling something like "c++ all combination in two series"

Where your series are "test" and "TEST" (or pseudo code'ishly "lower(word) and upper(word)")

Here are a few things I came across which might help you:
http://rg03.wordpress.com/2007/04/17...utations-in-c/
http://www.codeguru.com/forum/archiv.../t-326694.html

Edit:
I also just came across this python code in another active thread, it might give you some ideas:
http://forums.remote-exploit.org/sho...61&postcount=3
(Though it doesn't seem quite as clean as some of the C++ I found while googling)
Looking at stuff now, thanks!

6. Here's one method that comes to mind:

Think of "test" as a binary number where 0's indicate lowercase letters and 1's indicate uppercase letters. Because "test" is all lowercase, it would be 0000. "tEst" would be "0100", and "TEsT" would be "1101".

To get all possible combinations, all you have to do is count in binary:

0000 = test
0001 = tesT
0010 = teSt
0011 = teST
0100 = tEst

Something like as follows:

(Disclaimer: Thrown together in ten minutes so likely to contains errors, bugs and oversights)

Code:
```#include <stdint.h>
#include <ctype.h>    /* tolower, toupper*/
#include <stdio.h>    /* puts */
#include <memory.h>   /* strlen */

void PrintCombos(char *const str)
{
uint_fast32_t cases;  /* Keep track of cases */

uint_fast32_t const one_past_max_count = (uint_fast32_t)1 << strlen(str);

for (cases = 0; one_past_max_count != cases; ++cases)
{

{
if (cases & mask) str[i] = toupper((char unsigned)str[i]);
else str[i] = tolower((char unsigned)str[i]);
}

puts(str);
}
}

int main(int argc, char **argv)
{
if (2 != argc) return 0;

PrintCombos(argv[1]);

return 0;
}```
A little extra code is required to get rid of duplicates (e.g. if the string contains numbers).

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•