# Random Character String Genration!!!



## roblooman (May 17, 2011)

Ok guys here is a hard one for you...i am an idea guy *not* a coder and have no way of being able to do this

the program i am working on requires much in the way of password keys.
now the *"keys"* are of lengths that extend well into the 1000 characters and anywhere into
the 1 million characters.(user specified)

so basicaly i need a function that will generate random characters to a txt file

it needs to cover these characters

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz 
(and editable to add more if i need to)

ok it has to be in either a batch file. or a vbs script i can call with these paramenters

start (scritp/batch/whatever) (number of chars to generate from user) (name of file to output to)

ok guys do your magic. i realy need this and i cant 
progress any further until i get it worked out.

now it needs to be random generation. these will be used in password keys
and also the length needs to be able to be chosen by the user/ me.,.... to a file i choose

like the example here

(call) 10000 -o mytxt.txt

tell program ( whatevername) to give me 10K random characters outputed to mytxt.txt

now i know how to change the call if its a script/ or a batch
but the call paramenters need to be very similar to that above in the example

thanks guys for all your help so far... and this forum is awsome BTW you guys rock..


----------



## Ent (Apr 11, 2009)

I can probably do this for you in VBS. However if you're working on a program already, it may be better to write a function in the language you're already using and incorporate it into your own work. All languages I know of allow you to use arrays, randomization and loops, which is all that's needed for this function.

Is there a particular reason you want the -o there?

I'll post back with a VBS script using the parameters _scriptname_ _Length File_, but I doubt it's the best option.
I can modify it if you need.


----------



## roblooman (May 17, 2011)

the -o is just my understand of an argument for .bat file to out put to a file name....dont worry about that if you can do what you said (scriptname) (number) (file name)

the program i am working on is basicaly a few batch scrips and vbs scripts that use and "engine " to encode and decode information...

i am trying to get it to work...having issues though

so far i am on the right path and as for the "keys" needed to make it all work i am stuck... i have alot of source code things i have found over the last couple of days that i can look at but not make much in the way of sense of them.

a simple vbs would be perfect. i can call it from a batch file and have it work in concert with the rest of the files...


Rob

ps thanks for the help


----------



## roblooman (May 17, 2011)

also........if i could be able to edit in some different characters into the script as i need them that would help as well... so far all i need is a-z, A-Z, 0-9... but that will change i fear.

even if it is something to the extend of

set charset=A-Z

or what ever. but to be able to go back and put in all the other i need as well
like......()[email protected]#$%^&*~`
but so far i am trying to aliminate the need for some of them as they are doing odd things in my scripts and .bat files and exiting out of files and putting in random spaces...

well if you help it would be much appreciated

Rob


----------



## Ent (Apr 11, 2009)

Here's a VBS script for you.


```
Randomize Timer ' Ensures a different set of characters each time it's run
Const ROC = 62 ' Sets how many options there are for each character. Must not drop below 62 (26+26+10)
Dim RO(62) ' Defines ROC spaces for characters that can be picked
Dim RandomText ' The actual string of random characters.

For x = 1 to 26 ' Sets the first 26 RO spaces to uppercase letters and the next 26 to lowercase letters
RO(x) = chr(64+x)
RO(x+26) = chr(96+x)
next
For x = 1 to 10 ' Sets the characters 53-62 to digits
RO(x+52) = chr(47+x)
next

' Add extra characters here.
If WScript.Arguments.Count = 2 Then
Length = WScript.Arguments.Item(0) ' Attempts to read length from command line parameters.
TargetFile = WScript.Arguments.Item(1)
else
TargetFile = "Random.txt"
Length = 16
msgbox("Parameters not correct" & VbCrLf & "Writing 16 characters to Random.txt")
end if


For X = 1 to Length
RandomText = RandomText & (RO(int(rnd()*ROC+1))) ' Generates a long string of random characters.
next

Set FSO = CreateObject("Scripting.FileSystemObject") ' Writes the long string to the file.
Set FileObject = FSO.OpenTextFile(TargetFile, 2, True)
FileObject.Write(RandomText)
FileObject.Close
```
If you do need to add characters manually, you'll need to do three things:
Change 62 in _Const ROC = 62 _to the number of characters you'll really have now.
Change 62 in _RO(62) _to the number of characters you'll really have now.
Add the character to RO in the position indicated in the comment. For example to add @ 
_RO(63) = "@"_


----------



## roblooman (May 17, 2011)

is there a way to get this into a vbscipt? instead of Wsp


----------



## Ent (Apr 11, 2009)

It is vbscript.
VBS is the language.
Wscript is just the program that Windows uses to execute scripts, including Javascripts and VBS scripts.
It stands, surprise surprise, for Windows Script.


----------



## roblooman (May 17, 2011)

could you check this out and see if there is a way to convert it over to vbs script
http://www.i-fubar.com/random-string-generator.php

i can undstand how it works and how to change the things i need to change like adding more characters if i need to...

is this portable to vbscript?

Rob


----------



## Ent (Apr 11, 2009)

For all intents and purposes that's exactly what I've done, I've just automated the adding in the letters and numbers, using 7 lines to do what would otherwise take 62. 

I'll add in 5 extra characters to my script so that you can see how to do it.


----------



## roblooman (May 17, 2011)

ok....cooll... i am standing by

Rob


----------



## Ent (Apr 11, 2009)

See the red sections for what's changed. It used to be 62 spaces because there are 26 uppercase characters, 26 lowercase letters, and 10 digits. It is now 67 because I've added the five characters @!$:?


```
Randomize Timer ' Ensures a different set of characters each time it's run
Const ROC = [COLOR=Red]67[/COLOR] ' Sets how many options there are for each character. Must not drop below 62 (26+26+10)
Dim RO([COLOR=Red]67[/COLOR]) ' Defines ROC spaces for characters that can be picked by the function.
Dim RandomText ' The actual string of random characters.

For x = 1 to 26 ' Sets the first 26 RO spaces to uppercase letters and the next 26 to lowercase letters
RO(x) = chr(64+x)
RO(x+26) = chr(96+x)
next
For x = 1 to 10 ' Sets the characters 53-62 to digits
RO(x+52) = chr(47+x)
next


[COLOR=Red]RO(63) = "@"
RO(64) = "!"
RO(65) = "$"
RO(66) = ":"
RO(67) = "#"
[/COLOR]


If WScript.Arguments.Count = 2 Then
Length = WScript.Arguments.Item(0) ' Attempts to read length from command line parameters.
TargetFile = WScript.Arguments.Item(1)
else
TargetFile = "Random.txt"
Length = 16
msgbox("Parameters not correct" & VbCrLf & "Writing 16 characters to Random.txt")
end if


For X = 1 to Length
RandomText = RandomText & (RO(int(rnd()*ROC+1))) ' Generates a long string of random characters.
next

Set FSO = CreateObject("Scripting.FileSystemObject") ' Writes the long string to the file.
Set FileObject = FSO.OpenTextFile(TargetFile, 2, True)
FileObject.Write(RandomText)
FileObject.Close
```


----------



## roblooman (May 17, 2011)

awww......cooll that will work...

ok now how do i call it? from the a batch


----------



## roblooman (May 17, 2011)

what are the limits to the script any pitfalss i need be awair of?


----------



## Ent (Apr 11, 2009)

Supposing that it's saved as Random.vbs.
To get a 10000 character string put into myRandomPassword.txt
You'd just type 
Random.vbs 10000 myRandomPassword.txt

If you don't specify the two parameters, including if you doubleclick on it, it defaults to 16 characters and Random.txt


----------



## roblooman (May 17, 2011)

aww sweet....

dude you are a life saver as is it will work.....

do you think you could help with some other stuff...

like a better way to combine all my .bat and .vbs together that make up this program into a simple exe file?


----------



## Ent (Apr 11, 2009)

I can't promise anything, but I'll do my best. It all depends on what you're trying to do and what you have. Turning it into one exe file could be a bit difficult, and all the more so if we're using different scripting techniques. It might be easier to start from scratch in a language that has all the capability needed. Again though, it depends on what you're actually trying to do.

One other annoying thing that I've just thought of, you can't add " to the list of characters to use in the method I said earlier, because it would think that the quote marked the end of the character to add.


----------



## Squashman (Apr 4, 2003)

If you are putting the output of this VBscript back into a Batch file it is going to choke on the special characters.

RO(63) = "@"
RO(64) = "!"
RO(65) = "$"


----------



## Ent (Apr 11, 2009)

I know. That's part of my reason for wanting to actually get it all together.


----------



## roblooman (May 17, 2011)

awwwww... i see....the generated data will be used for a key pass that the program looks for to help encode the data.....

my understandin...aside....will keeping the files in vbs help in the porting over to an exe later...

right now its all just vbs and .bat



Rob


----------



## Squashman (Apr 4, 2003)

You are wasting your time if you eventually want to port this over to a standalone executable program. Programming in batch and vbscript isn't exactly a one to one ratio if you want it programmed in C++ or .NET.


----------



## roblooman (May 17, 2011)

aww....so its a start over scenereo then..???

hmmm....ill mull it over..


----------



## Ent (Apr 11, 2009)

Let's just stop this for a moment and evaluate what we need to accomplish.

From your posts thus far I've gleaned that you want to create some manner of file encryption system, and you want this to consist of a single executable file. It has to be able to handle text files and binary files. And at some point you expect that a string of random values will be useful, I assume as a key.

However we don't know anything more than that. As a result we cannot really advise you on how best to proceed. However I do not believe that you'll be able to even approach what you're after with batch or even VBS. It needs a proper programming language, not a scripting one. Moreover if you try to use two or more languages you inevitably create complications.

Therefore please can you explain, in as much detail as possible, what you want to program and why.
Rather than helping with individual modules that we don't have the background to make fit together, We'll start by deciding what is the most appropriate language to program in, so that we don't end up having to rewrite the whole thing.

Then we can help you to actually program it.

I personally would be willing to help you implement any difficult function that is within my ability to find out how to do, especially if I _can't_ do it already. My coding abilities are still young and any challenge helps to improve them. I'm sure the same could be said of the others here, except that they've got a lot more experience than I. But we can't do that unless we know where the function in question fits with the rest of the program, otherwise it *won't* fit. We can also give you some pointers to help with the bits that you'll have to code.

It isn't quite a start over. The concepts of what you've got so far will be useful for one thing. Without more information I have to agree with Squashman though, and time you spend working as you are now probably equals time you waste.


----------



## roblooman (May 17, 2011)

ok apparently i haven't addressed some issues brought up...and concerning this thread and others i have....

ok....
1) i am not a coder...i am just a random chump trying to make a cool program the hard way.
2) My "program" is a cypher process based on an "engine" provided by my buddy its based after the enigma machine from the ww2 era ///he works all the time and dosent have time to sit with me and code so i am flying solo here on this.
3)i do not own the source code it's the other guys i am working with, and from what he says its all in C. exept for my bit. which currently is in batch and vbs files 
4)i am adding functionality to the already C code he has witch he gave me that uses the cmd promt to run its already compiled into an exe. i am doing bats and vbs's where i can to make the "engine" 
he gave me do tricks
5) the parts i am working on are these "tricks" or the processess that make the "engine" more then just an enigma clone but a whole Cypher program that has a HUGE bit depth that dwarfs current standards into nothing. AES, DES, triple DES 256 bit encryption standards pale in the 10,000 bit depth i have already achieved with my meassily batches and vbs's.
6) what i am needing help on guys is the small areas.....i am not proficient in. like coding vbs's and batch techniques i don't know. (i only have rudimentary skill in)..i am more an idea guy and trying to implament these idea are......failing hard!!! lol

ok......part of the last process thats not working correctly was the text file spliter...
most poeple will not write whole messages that are 3 lines or more. but to work into my process so far i need 3 peices exactly. so far i got a working version of that. in another thread. *cool*...*BUT* so far there are issues with the lines not coming in correctly and some characters being kicked out((this is a cypher program that uses the ascii character set.)). i attribut this to the <return> button characters that give new lines and the other special characters getting in the way of the code.

so i can get the dude i am working with single out the offending characters from the cypher program so when i do use them i can use them for getting rid of (delimited) value's using a slick batch or vbs.

that way i can instead of split the original file into 3 parts.(which is not gelling with the process now)that will get processed by the "engine" i can add "padding" instead to the data and process the 3 parts as

(part 1 PADDING)
(part 2 Messages)
(Part 3 PADDING)

seperated by some kind of *(character [email protected]#$%^&*(){}|:"<>?/.';\][)* that i can later delete later in the process.

i am sorry i cant give out the dude source code its his.
but the file i have so far you guys have helped with so far. so there i am

sorry ENT, and SHquWASH

beyond this i dont know what to say but please help...

Rob


----------



## roblooman (May 17, 2011)

yes.....its a encryption program.
i already have the key pass maker (i worked on that with my buddy already)
now i am just trying to work out the bugs in the process itself .

i originally came up with the idea to separate a message or document into 3
(by lines / or characters) and process each separately with different keys....

cool trick i thought...but the implementation was a little to much and although works like it supposed to... dosent gell with the vbs's and batches we have already.

because of special characters that the main program uses to encode with.

so.........whats needed right now is a fix to separate data....
after its been put together....and the only way i can see that happening is the use of a character to delete the padding scheme i mentions above.


any takers?
Rob


----------



## roblooman (May 17, 2011)

Ent said:


> Here's a VBS script for you.
> 
> 
> ```
> ...


dude thanks to this you helped me and the dude i am working with work out a scheme to get padding into our program thanks...

Rob


----------



## Squashman (Apr 4, 2003)

Sounds like you need to take a programming class or rent a programmer.


----------



## roblooman (May 17, 2011)

you probably right.....


----------



## Ent (Apr 11, 2009)

He is right. We can help here, but we don't have the time or resources to do everything for everyone.
By the way, if you do hire someone, they'll almost certainly either need access to this guy's code or they'll have to write it from scratch. It's not easy to write a program when you don't know where it fits in with code that's already there. 

It is a really useful skill being able to write a bit of computer code, if you do want to give it a shot at learning the thing for yourself.


----------



## roblooman (May 17, 2011)

i am trying so for with simple bats and vbs's but its a steep hill the learning curve
i am more an ideas guy.....but the more time i spend on working this the better i understand it....


----------

