| 1. |
Solve : One random letter variable? |
|
Answer» How to I make a variable that displays a single random letter a-z. @echo off Okay this is helpful but is there a way a can change this to make a random 26 character alphabet variable? Randomized alphabet string 26 chars long, (no repeats) Code: [Select]@echo off REM 65 for upper case, 97 for lower case set CaseType=97 > Randalphabet.vbs echo randomize timer >> Randalphabet.vbs echo RandAlphabet="" >> Randalphabet.vbs echo Do >> Randalphabet.vbs echo randchar = Chr(Int(26*Rnd+%CaseType%)) >> Randalphabet.vbs echo If Instr(RandAlphabet, randchar) = 0 Then RandAlphabet = RandAlphabet ^& randchar >> Randalphabet.vbs echo if len(RandAlphabet) = 26 Then exit Do >> Randalphabet.vbs echo Loop >> Randalphabet.vbs echo wscript.echo RandAlphabet REM ----------------------------------------------- REM Here you use it for /f "delims=" %%A in ('cscript //nologo Randalphabet.vbs') do set Randalphabet=%%A echo %Randalphabet% Examples Code: [Select]cjdmtelkufvywozsnbghxairqp pojqhbyftgweviadlxzrsncumk ayoublqmvzdhfkxpiwcngsterj Quote from: Salmon Trout on April 17, 2016, 01:27:48 AM Randomized alphabet string 26 chars long, (no repeats) thank you this is exactly what i need Have you noticed what happens if you delete or comment out the randomize timer line in the vbs? Quote from: Salmon Trout on April 17, 2016, 12:53:27 PM Have you noticed what happens if you delete or comment out the randomize timer line in the vbs? the only thing that i realized is that it goes to an error on second run due to the ">" sign not being a ">>", what exactly is happening? Quote from: zask on April 22, 2016, 12:37:23 PM the only thing that i realized is that it goes to an error on second run due to the ">" sign not being a ">>", what exactly is happening?Comment out the VBS line being written like this (that's a single quote just before the randomize keyword) (etc) > Randalphabet.vbs echo 'randomize timer (etc) Quote from: Salmon Trout on April 22, 2016, 12:43:01 PM Comment out the VBS line being written like this (that's a single quote just before the randomize keyword) Oh okay i see now, thats a really cool trick . Now i came up with this using some of the code that was provided by you guys and some old code i had LAYING around. this code is supposed encrypt a text file full of batch commands, then make a decrypter to take the encrypted text file, decrypt each command, and execute it within the same batch file. Now i am having a problem, each line in the text file is supposed placed in a separate variable to encrypt/decrpyt them one at a time, but if i wanted to use variable in the encrypted text file (For example~ %Variable%, %%V, !Variable!), they wont work correctly. It would appear "%Variable%" rather than what the substitution of what the variable should be set to. for example if i typed something like this in a text file and encrypted it; color 17 echo hello pause everything would work completely fine but if i tried to type something like this; color 17 set a=hello echo %a% pause When the decrypter.bat file would decrypt then execute the commands it would display as this "%a%" instead of "hello" Is there a way to fix this? here is my code so far. @ECHO Off echo encrypt batch file echo. Setlocal EnableDelayedExpansion Set _RNDLength=8 Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 Set _Str=%_Alphanumeric%987654321 :_LenLoop IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop SET _tmp=%_Str:~9,1% SET /A _Len=_Len+_tmp Set _count=0 SET _RndAlphaNum= :_loop Set /a _count+=1 SET _RND=%Random% Set /A _RND=_RND%%%_Len% SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1! If !_count! lss %_RNDLength% goto _loop REM 65 for upper case, 97 for lower case set CaseType=97 > Randalphabet.vbs echo randomize timer >> Randalphabet.vbs echo RandAlphabet="" >> Randalphabet.vbs echo Do >> Randalphabet.vbs echo randchar = Chr(Int(26*Rnd+%CaseType%)) >> Randalphabet.vbs echo If Instr(RandAlphabet, randchar) = 0 Then RandAlphabet = RandAlphabet ^& randchar >> Randalphabet.vbs echo if len(RandAlphabet) = 26 Then exit Do >> Randalphabet.vbs echo Loop >> Randalphabet.vbs echo wscript.echo RandAlphabet for /f "delims=" %%A in ('cscript //nologo Randalphabet.vbs') do set Randalphabet=%%A del Randalphabet.vbs set /A CREATEKEY=%random% %%200 +2 set /P "FILEA= Enter the name of the text file that you wish to encrypt (Example; "Somefile") : " set /P "FILEB= Enter the new name for the text file that you wish to encrypt (Example; "NewFile") : " Setlocal EnableExtensions for /f "delims=" %%A in (%FILEA%.txt) do ( Set /a C+=1 Set X[!C!]=%%A set CHECKPASSWORD=%%A set CHECKKEY=%%B set CHAR=0123456789%Randalphabet% for /l %%C in (10 1 36) do ( for /f %%D in ("!CHAR:~%%C,1!") do ( set /a MATH=%%C*%CREATEKEY% for /f %%E in ("!MATH!") do ( set "CHECKPASSWORD=!CHECKPASSWORD:%%D=-%%E!" ) ) ) echo !CHECKPASSWORD! >> %FILEB%.!_RndAlphaNum! ) Set X echo @ECHO Off >> Decrypt.bat echo. >> Decrypt.bat echo Setlocal EnableExtensions EnableDelayedExpansion >> Decrypt.bat echo for /f "delims=" %%%%A in (%FILEB%.!_RndAlphaNum!) do ( >> Decrypt.bat Setlocal DisableExtensions DisableDelayedExpansion echo Set /a C+=1 >> Decrypt.bat echo Set X[!C!]=%%%%A >> Decrypt.bat echo set CHECKPASSWORD=%%%%A >> Decrypt.bat echo set CHECKKEY=%%%%B >> Decrypt.bat echo set CHAR=0123456789%Randalphabet% >> Decrypt.bat echo. >> Decrypt.bat echo for /l %%%%C in (10 1 36) do ( >> Decrypt.bat echo for /f %%%%D in ("!CHAR:~%%%%C,1!") do ( >> Decrypt.bat echo set /a MATH=%%%%C*%CREATEKEY% >> Decrypt.bat echo for /f %%%%E in ("!MATH!") do ( >> Decrypt.bat echo. >> Decrypt.bat echo set "CHECKPASSWORD=!CHECKPASSWORD:%%%%E=%%%%D!" >> Decrypt.bat echo ) >> Decrypt.bat echo ) >> Decrypt.bat echo ) >> Decrypt.bat echo for /f %%%%F in ("!CHECKPASSWORD!") do ( >> Decrypt.bat echo set "CHECKPASSWORD=!CHECKPASSWORD:-=!" >> Decrypt.bat echo !CHECKPASSWORD! >> Decrypt.bat echo ) >> Decrypt.bat echo ) >> Decrypt.bat echo Set X >> Decrypt.bat I have a working example of some encrypted commands that do work, they shoud help give example of what im trying to do, but you have to download it here. http://www.filedropper.com/batchencrypter_2 It would be nice if Zask could tell us why he wants to do this. If it is just for the fun of doing a task in DOS the hard way, that is OK. But if Zask NEEDS a quick and effective solution to a piratical problem, he might say so. Here is why I ask. He is using a Random generator to make a sequence that is not random. He wants a re-ordered sequence of the Alphabet. It is a table where are letters are present, but not in an obvious order. Such tables do not need the random generator. Such are used in some types of encryption methods. And it can be done in batch, but if anybody finds the code your method is no longer a secret. Quote from: Geek-9pm on April 24, 2016, 10:54:03 PM It would be nice if Zask could tell us why he wants to do this. I understand that, and yes you are correct, i do prefer doing things in dos the hard way, that's just the type of person i am. I don't really care if other people find my code because i just program batch for a hobbie and i do this to learn, when i am not programming in dos i am usually learning other programming language at school, and that's where i usually ask questions on my work. But when I program batch the internet is where i come to learn. There really isn't much reason to why i needed the random alphanumeric code, but one reason is because when "a" is assigned to "1", and "b" to "2", "c" to "3", and so forth. it would be to obvious. I just wanted it assigned to a random alphabet so that "a" could be "5", or "z" could be "12". And also because i wanted the sequence to change each time. It doesn't necessarily make the code anymore harder to decipher but it does give some people with less knowledge less more time to reverse the code (Not much though). But do acknowledge that a lot of the help i get from you guys is very much appreciated. So do you know a way that i can make it possible to get the variables to work? I cant currently get my head wrapped around this. They display what appears textualized, but they don't actually work.Simple number sequnces. https://www.mathsisfun.com/numberpatterns.html This can be one way of making a unusual sequence. But you can also do it by hand and get good results. The idea is a foundation on which to build. You can add complexity to it later. Partial example: (only 8 items to SHOW the idea.) Code: [Select]1 2 3 4 5 6 7 8 < order A B C D E F G H 5 2 7 4 1 6 3 8 < scramble In this group on 8 items are shown. The index is 5. Only two items are m is not scambled. This does not matter, the set is still hard to guess. No,this is not MS-DOS code, but ut shows the value of having some kind on idea or conceptin mind. This modloe does not need the random funtion. But requires aknowledge of number sequences. using this, yu can hand code tables of numbers. What I am sayhing is that you need to do more "top down" thinking before you code. Have some notes and examples of what yu can do by hand and then think about making code for it. Quote from: Geek-9pm on April 25, 2016, 05:49:54 PM Simple number sequnces. |
|