Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I have been trying to make my own base in batch, and I use base64 at the same time.

I already have a system setup that will transfer it from base64 to decimal, and I have it like this:

MSAyIDMgNCA1IDYgNyA4IDkgMTAgMTEgMTIgMTMgMTQgMTUgMTYgMTcgMTggMTkgMjAgMjEgMjIgMjMgMjQgMjUgMjY=

to this:

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

I made the code to automatically output it to a file, but now I don't know how to make them all into different variables like variable1=1, varable5=5, and so on, and then there will be text at the end which I want it to be it's own different variable like "FinalText=(whatever text the user puts)" and I would really appreciate the help.

The numbers will be different each time, so Variable5 could equal 21 for all I know.

What I have tried:

Looking and attempting solutions
Posted
Updated 31-Dec-21 10:39am
Comments
Richard MacCutchan 19-Dec-21 3:48am    
"so Variable5 could equal 21 for all I know."
Well if you don't know ...
l o o l 31-Dec-21 13:44pm    
then? what @Richard MacCutchan?
l o o l 31-Dec-21 17:31pm    
..I want it to be it's own different variable like "FinalText=(whatever text the user puts)... I didn't understand this part, you're going to request and get input from the user, is that it? For input, try read about set /p command: set /p "_var=text asking for user input: "

1 solution

Well, in theory, what you need to do would be:

1) get the decoded strings of a pre-existing string present in a given file

2) save this string/line obtained from the file in a variable

3) generate variable substring using space as delimiter, one by one

3) have access to the variables resulting from the substring in an accessible way

4) treat variable by variable in a predictive way, and ordering for defining each value

_ _ _ _

You can do is add (append) to your `bat` the strings in base64, this will occur (usually) will be on the last line, and your code will make the bat exit before executing this line as/equal to commands.

For this case, your program would not print the strings to a file (say "outputs_some_file.txt"), but would add the strings "<-----BEGIN -----" and "----END ----->" and append the bat itself:

CMD/BAT
<-----BEGIN -----[your_string_b64_came_here]-----END ----->

:: For example, this line would be added to your bat:  
<-----BEGIN -----OSAxMSA4IDQgMTUgMjIgNyAzIDEgMjAgMiAxMiAyNiAyNCA1IDIzIDE4IDE3IDI1IDEwIDIxIDYgMTMgMTQgMTkgMTYNCg===-----END ----->


Your bat will decode the base64 strings contained in them in a separate file, and after that step, it takes this separate file and sets a variable (_string_0), with the decoded content.

Once this content is decoded and saved in a variable, this file is no longer useful, so as a dispensation, so we can create a copy of the bat without the base64 strings, to restore the bat to its original state/content, using move command.

Your bat without the line added by your program:

CMD/BAT
@echo off

setlocal enabledelayedexpansion
cd /d "%~dp0" && 2>nul set /a _i=-!_i!
>nul CertUtil -f -decode "%~f0" .\File.dat

set /p _string_0=<.\File.dat && findstr /vb ^< <"%~f0" >.\File.dat
set "_string_0=%_string_0: =" & set /a _i+=1+0 & set "_string_!_i!=%"

:: access anytime you need any of the 26 (_var_0 - _var_25) variables ::
for /L %%L in (0 1 !_i!)do echo\Your variable _string_%%L: !_string_%%L!

echo\use for example the fifth value/variable (!_string_5!) where you need, and
echo\use for example the thirteenth value/variable (!_string_13!) where you wanna

2>nul >nul move /y .\File.dat "%~f0" | endlocal & goto :eof


Your bat with the (last) line added by your program:
CMD/BAT
@echo off

setlocal enabledelayedexpansion
cd /d "%~dp0" && 2>nul set /a _i=-!_i!
>nul CertUtil -f -decode "%~f0" .\File.dat

set /p _string_0=<.\File.dat && findstr /vb ^< <"%~f0" >.\File.dat
set "_string_0=%_string_0: =" & set /a _i+=1+0 & set "_string_!_i!=%"

:: access anytime you need any of the 26 (_var_0 - _var_25) variables ::
for /L %%L in (0 1 !_i!)do echo\Your variable _string_%%L: !_string_%%L!

echo\use for example the fifth value/variable (!_string_5!) where you need, and
echo\use for example the thirteenth value/variable (!_string_13!) where you wanna

2>nul >nul move /y .\File.dat "%~f0" | endlocal & goto :eof
<-----BEGIN -----OSAxMSA4IDQgMTUgMjIgNyAzIDEgMjAgMiAxMiAyNiAyNCA1IDIzIDE4IDE3IDI1IDEwIDIxIDYgMTMgMTQgMTkgMTYNCg==-----END ----->


Outputs:
CMD/BAT
Your variable _string_0: 9
Your variable _string_1: 11
Your variable _string_2: 8
Your variable _string_3: 4
Your variable _string_4: 15
Your variable _string_5: 22
Your variable _string_6: 7
Your variable _string_7: 3
Your variable _string_8: 1
Your variable _string_9: 20
Your variable _string_10: 2
Your variable _string_11: 12
Your variable _string_12: 26
Your variable _string_13: 24
Your variable _string_14: 5
Your variable _string_15: 23
Your variable _string_16: 18
Your variable _string_17: 17
Your variable _string_18: 25
Your variable _string_19: 10
Your variable _string_20: 21
Your variable _string_21: 6
Your variable _string_22: 13
Your variable _string_23: 14
Your variable _string_24: 19
Your variable _string_25: 16
use for example the fifth value/variable (22) where you need, and
use for example the thirteenth value/variable (24) where you wanna


What you are doing is using a mixed set command with auto variable expansion based on a delimiter, in your case the space:
CMD/BAT
set "_string_0=%_string_0: =" & set /a _i+=1+0 & set "_string_!_i!=%"
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900