RCG needs help with possible poison characters (getting clos
Posted: 29 Oct 2012 17:46
I created a RCG, nothing new there as they are a dime a dozen. But i need help on getting the Extended Character Set (as well as the Special) to generate properly. it breaks when using "E" or "S" for the character set, but all the others; A, AN, H, N work as designed.
you can run the program either by:
1) typing in Rand7
and use E or S for the CharSet
or
2) typing in Rand7 4 4 4 E N
There are two other places that could look nicer , these are:
1) if defined rand16 set Result!maxcount!= found at the outerend loop
and
2) if defined result%%a if "%1"=="/s" endlocal & found at the end loop
i was able to put the #2 in a for /L loop but couldn't fathom a way to condense it further
trying to put #1 in a for /L loop didn't work at all. i would appreciate any help on making these more succinct code even though it works as it is.
note: i did write a basic program that worked on all characters but the double quote and wanted to achieve the same with a batch file.
idea's or thoughts?
rand7
you can run the program either by:
1) typing in Rand7
and use E or S for the CharSet
or
2) typing in Rand7 4 4 4 E N
There are two other places that could look nicer , these are:
1) if defined rand16 set Result!maxcount!= found at the outerend loop
and
2) if defined result%%a if "%1"=="/s" endlocal & found at the end loop
i was able to put the #2 in a for /L loop but couldn't fathom a way to condense it further
trying to put #1 in a for /L loop didn't work at all. i would appreciate any help on making these more succinct code even though it works as it is.
note: i did write a basic program that worked on all characters but the double quote and wanted to achieve the same with a batch file.
idea's or thoughts?
rand7
Code: Select all
@echo off
echo.
set QtySets=&set CharSet=&set SepStat=&set SepChar=&set ByteCount=&set MaxLoop=
set result1=&set result2=&set result3=&set result4=&set result5=&set result6=
set result7=&set result8=&set result9=&set result10=&set result11=&set result12=
set result13=&set result14=&set result15=&set result16=
set maxcount=0&set count=0
setlocal EnableExtensions EnableDelayedExpansion
if "%1"=="" goto :askque4
if /i "%1"=="/h" goto :help
if "%1"=="/?" goto :help
if /i "%1"=="/s" goto :askque4
:: Maxloop QtySets ByteCount CharSet SepStat but not SepChar
if "%1" GTR 0 if "%2" GTR if "%3" GTR 0 if not "%4"=="" if not "%5"=="" (
set MaxLoop=%1
set QtySets=%2
set ByteCount=%3
set CharSet=%4
set SepStat=%5
goto :initset
)
goto :askque4
:help
echo %0 will create a block of random code based on your input.
echo.
echo The program will ask for character set, loop count, byte size and repeat byte.
echo.
echo The max for loop count is 64
echo The max for byte size is 16
echo The max for repeat byte is 16
echo.
echo Thus the max block size is 16K, you will need to extend the DOS console
echo session so that the screen buffer width is 250 or greater, so that will
echo fit the entire block on a page. You will need to be able to scroll to
echo capture the entire block. Remember to press Enter to complete the copy.
echo.
echo The character set can be one of the following: Unique Key's
echo ________ ___________________________________ ____________
echo.
echo Alpha - Upper and Lower Case A-Z, a-z ^(52^)
echo Extended - Alpha + Number + Special Characters ^(93^)
echo Hex - Hexadecimal A-Z,0-9 ^(16^)
echo Number - Numbers 0-9 ^(10^)
echo AlphaNum - AlphaNumeric A-Z, a-z, 0-9 ^(62^)
echo.
echo This program will produce ^("to the best of its known abilites"^) completely
echo random code.
echo.
echo The default charcter set is Hex, Loop Count, Byte Size and Repeat Byte is 4.
echo This is a 64 byte block of random code to use as you deem fit.
echo Max possibilites 1.157920892373162e+077
echo.
echo Tip: You can use the Edit-^>Mark command of the console to mark a block of text,
echo hit enter to save selected text. Then you can paste into another document or
echo program.
echo.
echo Tip: Set the properties of the CMD.EXE to Quick Edit mode. Then mark text with
echo Left click and Drag, Right click to copy selected text. Paste to document or
echo program.
echo.
echo Tip: to save the result(s) to the environment table, use the /s switch. Type
echo "SET result" to view the ouptut of %0. Note: Running a subsuquent %0
echo without the /s switch will clear the previous output to the environment table.
echo.
echo The Author ^(and other Distributers^) of this software will not be held
echo responsible for any damages caused by said software. The is no warranty,
echo implied or otherwise. Tbis is to be used for your education of Random Code
echo Generator's.
goto :eof
:askque4
:: find out which character set to use
echo CharSet(Possibilities) Expanded
echo ====================== ====================================
echo Alpha^(52^) A-Z, a-z
echo AlphaNumeric^(62^) A-Z, a-z, 0-9
echo Extended^(93^) A-Z, a-z, 0-9, All exc "^!","%%"
echo Hex^(16^) A-F, 0-9
echo Numbers^(10^) 0-9
echo Special^(33^) All exc "^!","%%"
echo.
set /p CharSet=Choose Character Set [A^/AN^/E^/H^/N^/S] ^<H^>
echo.
if "%CharSet%"=="" set CharSet=H
if /i not "%CharSet%"=="A" if /i not "%CharSet%"=="E" if /i not "%CharSet%"=="H" if /i not "%CharSet%"=="N" if /i not "%CharSet%"=="AN" if /i not "%CharSet%"=="S" goto :askque4
:askque3
:: how many time to repeat random request
set /p MaxLoop=How many times to repeat selection? [1-64] ^<4^>
echo.
if "%MaxLoop%"=="" set MaxLoop=4
if %MaxLoop% GTR 0 if %MaxLoop% LSS 65 goto askque2
echo.
echo %MaxLoop% not in the expected range [1-16]
echo.
goto askque3
:askque2
:: get the amount of characters to display per string
set /p byteCount=How many digits do you want to display per pair? [1-16] ^<4^>
echo.
if "%byteCount%"=="" set byteCount=4
if %byteCount% GTR 0 if %byteCount% LSS 17 goto askque1
echo.
echo %byteCount% not in the expected range [1-16]
echo.
goto askque2
:askque1
:: get the amount of %byteCount% byte pairs to be generated and displayed
set /p QtySets=How many sets of %byteCount% do you want to generate? [1-16] ^<4^>
echo.
if "%QtySets%"=="" set QtySets=4
if %QtySets% GTR 0 if %QtySets% LSS 17 goto :askque5
echo %QtySets% not in the expected range [1-16]
echo.
goto askque1
:askque5
:: ask about seperator usage
set /p SepStat=Use a seperator between sets? [Y-N] ^<N^>
echo.
if "%SepStat%"=="" set SepStat=N & goto :initset
if /i "%SepStat%"=="Y" set SepStat=Y & goto :askque6
if /i "%SepStat%"=="N" set SepStat=N & goto :initset
goto :askque5
:: ask about type of seperator
:askque6
set /p SepChar=Use a Dash or Space as delimiter? [D-S] ^<S^>
echo.
if "%SepChar%"=="" set SepChar=S & goto :initset
if /i "%SepChar%"=="S" set SepChar=S & goto :initset
if /i "%SepChar%"=="D" set SepChar=D & goto :initset
goto :askque6
:: loop to create string value; character setLoop Count, ByteCount RepeatByte
:: eg. 519B or 6C2B0A or 0F14A28CD or AlFGHJdKaceD, etc...
:initset
REM if /i "%1"=="/repeat" echo \%QtySets%\ /%SepStat%/ \%ByteCount%\ /%Maxloop%/ \%CharSet%\
REM echo \!CharSet!\ /!Maxloop!/ \!ByteCount!\ /!QtySets!/ \!SepStat!\
:: make the SPECIAL characters
:: note: some ommited, see end of list - "RESERVED"
:: make the A-Z characters
:: make the a-z characters
:: make the 0-9 characters
set n=0123456789
set h=ABCDEF0123456789
set a=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
set an=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
set "e=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`@#$^&:;_/.,^*^-^+^=^\^|^]^[^{^}^'^?^(^)^<^>^ ^^^""
set "s=^~^`^@^#^$^^^&^:^;^_^/^.^,^*^-^+^=^\^|^]^[^{^}^'^?^(^)^<^>^ ^^^""
rem SPACE appears to work but not yet tested fully, appears in CharSet after the ^>
SET "RESERVED1=^ "
rem the two reserved characters do not work, how to get them to work?
SET "RESERVED2=^!"
SET "RESERVED3=^%"
:: unrem to see the extended set
REM echo %e%
:: unrem to see the special set
REM echo %s%
:: set random to eval
set /a eval1=%random% %% 10
set /a eval2=%random% %% 16
set /a eval3=%random% %% 52
set /a eval4=%random% %% 62
set /a eval5=%random% %% 93
set /a eval7=%random% %% 32
set /a eval6=%Maxloop% * %byteCount% * %QtySets%
if %Maxloop% GTR 1 (echo Generating a block size of %eval6% characters) else (
echo Generating a string size of %eval6% characters)
echo.
:maxloop
REM echo off
REM pause > nul | echo Breakpoint1
set /a maxcount=%maxcount% + 1
:continue
set outercount=0
:outrloop
set /a outercount=!outercount! + 1
set count=0
:innrloop
set /a count=count + 1
:: get return of random mod based on CharSet
:: Has NOT Passed Range Testing
:: set the character set
:askque7
:: goto CharSet and get random character
if /i "%CharSet%"=="A" set /a eval3=%random% %% 52 & set randval=!a:~%eval3%,1! & goto :charstsk
if /i "%CharSet%"=="E" (
set /a eval5=%random% %% 92
if !eval5! LEQ 62 set randval=!an:~%eval5%,1! & goto :charstsk
if !eval5! GTR 62 set /a eval5=!eval5! * 2 - 125
set randval=!s:~%eval5%,1!
) & goto :charstsk
if /i "%CharSet%"=="H" set /a eval2=%random% %% 16 & set randval=!h:~%eval2%,1! & goto :charstsk
if /i "%CharSet%"=="N" set /a eval1=%random% %% 10 & set randval=!n:~%eval1%,1! & goto :charstsk
if /i "%CharSet%"=="AN" set /a eval4=%random% %% 62 & set randval=!an:~%eval4%,1! & goto :charstsk
if /i "%CharSet%"=="S" set /a eval6=%random% %% 32 & set randval=!s:~%eval7%,1! & goto :charstsk
goto askque7
:charstsk
:: sets the nth character of randval
set randval_!count!=!randval:"=!
if !count!==%byteCount% goto innrend
goto innrloop
:innrend
set Rand!outercount!=%randval_1%%randval_2%%randval_3%%randval_4%%randval_5%%randval_6%%randval_7%%randval_8%%randval_9%%randval_10%%randval_11%%randval_12%%randval_13%%randval_14%%randval_15%%randval_16%
if !outercount!==%QtySets% goto outerend
:: repeat QtySets times
goto outrloop
:outerend
:: now display the %byteCount% byte string
REM echo if /i "%SepStat%"=="N"
if /i "%SepStat%"=="N" (set Result!maxcount!=%Rand1%%Rand2%%Rand3%%Rand4%%Rand5%%Rand6%%Rand7%%Rand8%%Rand9%%Rand10%%Rand11%%Rand12%%Rand13%%Rand14%%Rand15%%Rand16%) & goto :showit
if /i "%SepStat%"=="N " (set Result!maxcount!=%Rand1%%Rand2%%Rand3%%Rand4%%Rand5%%Rand6%%Rand7%%Rand8%%Rand9%%Rand10%%Rand11%%Rand12%%Rand13%%Rand14%%Rand15%%Rand16%) & goto :showit
if "%SepChar%"=="" set "SS= "
if /i "%SepChar%"=="S " (set "SS= "
) else (
set "SS=-")
REM for /l %%b in (16,-1,1) do (
rem how to make this look better rem
if defined rand16 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10%%SS%%Rand11%%SS%%Rand12%%SS%%Rand13%%SS%%Rand14%%SS%%Rand15%%SS%%Rand16% & goto :showit
if defined rand15 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10%%SS%%Rand11%%SS%%Rand12%%SS%%Rand13%%SS%%Rand14%%SS%%Rand15% & goto :showit
if defined rand14 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10%%SS%%Rand11%%SS%%Rand12%%SS%%Rand13%%SS%%Rand14% & goto :showit
if defined rand13 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10%%SS%%Rand11%%SS%%Rand12%%SS%%Rand13% & goto :showit
if defined rand12 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10%%SS%%Rand11%%SS%%Rand12% & goto :showit
if defined rand11 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10%%SS%%Rand11% & goto :showit
if defined rand10 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9%%SS%%Rand10% & goto :showit
if defined rand9 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8%%SS%%Rand9% & goto :showit
if defined rand8 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7%%SS%%Rand8% & goto :showit
if defined rand7 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6%%SS%%Rand7% & goto :showit
if defined rand6 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5%%SS%%Rand6% & goto :showit
if defined rand5 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4%%SS%%Rand5% & goto :showit
if defined rand4 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3%%SS%%Rand4% & goto :showit
if defined rand3 set Result!maxcount!=%Rand1%%SS%%Rand2%%SS%%Rand3% & goto :showit
if defined rand2 set Result!maxcount!=%Rand1%%SS%%Rand2% & goto :showit
if defined rand1 set Result!maxcount!=%Rand1% & goto :showit
rem )
:showit
REM pause > nul | echo Breakpoint2
:: now suppress trailing spaces
for /f "tokens=1-%byteCount% delims= " %%a in ("!Result%maxcount%!") do (
if "!Result%maxcount%:~-1!"==" " set Result%maxcount%=!Result%maxcount%: =!
:: show on screen
if %maxcount% LSS 10 (
REM echo result1 is %result1%
set Result!maxcount!=!Result%maxcount%! & echo %%^Result!maxcount!%%^ = !Result%maxcount%!) else (
set Result!maxcount!=!Result%maxcount%! & echo %%^Result!maxcount!%%^ = !Result%maxcount%!)
)
:: check if maxcount is equal to maxloop, if yes end, if not goto maxloop
if %maxcount% GEQ %MaxLoop% goto :end
goto maxloop
:end
echo.
REM if /i "%1"=="/r" endlocal & set QtySets=%QtySets% & set CharSet=%CharSet% & set outercount=0 & set maxcount=0 & set count=0 & set SepChar=%SepChar% & set SepStat=%SepStat% & set Maxloop=%Maxloop% & set ByteCount=%ByteCount% & goto :eof & echo Saving Presets...
if /i "%1"=="/s" (
for /l %%a in (16,-1,1) do (
rem how to make this look better rem
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10% & set Result11=%Result11% & set Result12=%Result12% & set Result13=%Result13% & set Result14=%Result14% & set Result15=%Result15% & set Result16=%Result16%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10% & set Result11=%Result11% & set Result12=%Result12% & set Result13=%Result13% & set Result14=%Result14% & set Result15=%Result15%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10% & set Result11=%Result11% & set Result12=%Result12% & set Result13=%Result13% & set Result14=%Result14%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10% & set Result11=%Result11% & set Result12=%Result12% & set Result13=%Result13%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10% & set Result11=%Result11% & set Result12=%Result12%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10% & set Result11=%Result11%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9% & set Result10=%Result10%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8% & set Result9=%Result9%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7% & set Result8=%Result8%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6% & set Result7=%Result7%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5% & set Result6=%Result6%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4% & set Result5=%Result5%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3% & set Result4=%Result4%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2% & set Result3=%Result3%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1% & set Result2=%Result2%
if defined result%%a if "%1"=="/s" endlocal & set Result1=%Result1%
)
)
if not "%1"=="/s" endlocal
:eof