Unhashing with certutil in batchfile - windows

So I'm learning about hashing in Windows Batchfile and I was wondering if there is a simple way to unhash hashed text.
To hash the text, I have been using this:
set /p input=Text:
echo %input%>%temp%\hashinput.tmp
CertUtil -hashfile %temp%\hashinput.tmp sha256 | findstr /v "hash">%temp%\hashoutput.tmp
set /p output=<%temp%\hashoutput.tmp
del %temp%\hashinput.tmp
del %temp%\hashoutput.tmp
echo %output%
All it's doing is sending the user input to a temporary file, hashing it and sending that to a temporary file and setting a variable to the output before removing the files.
After some looking around I, have been unable to find a way to unhash text using CertUtil or any other commands. If there is an easy way I would love to know how.

There is no feasible way to get the original input from the hash, that is the whole point. You can try brute force by trying all possible inputs but that is not practical, it will take way too much time.
Another name for a hash is a one-way function...

Related

Windows batch scramble/unscramble filenames

I'm looking for a way to scramble/unscramble (encrypt/decrypt) the filenames of every file in a directory via batch script. One .bat file would encrypt the filenames in the current directory, and another would decrypt them.
I have an idea as to how this might work, but lack the batch file skills/experience to make it happen on my own: Have the encryption script find the ASCII value of each character in each filename, increment each character by a certain amount, and then rename each file accordingly. The decryption script would function in a similar but opposite manner. Just an idea - as long as the filename gets fully scrambled and unscrambled, I will be happy.
Any batch file wizards out there willing to lend a hand? Thanks in advance!
Here is a solution that utilizes JREPL.BAT - a regular expression find/replace utility. JREPL is pure script (hybrid JScript/batch) that runs natively on any windows machine from XP onward - no 3rd party exe required.
I used the simple ROT13 substitution cipher Running the script once encrypts the names. Running a second time restores the names to the original values. I chose to encrypt only the file name, not the extension. It would be easy to modify to encrypt the extension as well.
encryptNames.bat
#echo off
pushd %1 .
call :sub
popd
exit /b
:sub Subroutine needed to guarantee %-f0 gives the correct value
setlocal
set "find=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
set "repl=NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
set "p=/(.*)/"
set "prepl={$1}"
for /f "delims=" %%C in (
'cmd /c "for %%F in (*) do #if "%%~fF" neq "%~f0" echo ren "%%F" "/%%~nF/%%~xF""^|jrepl find repl /t "" /p p /prepl "{$1}" /v'
) do echo %%C&%%C
Calling encryptNames.bat without any argument will encrypt all files in the current directory (except for the encryptNames.bat file itself)
You can encrypt the names in any folder by passing the folder path as an argument. For example:
encryptNames c:\my\folder\to\be\encrypted
Note that encryptNames.bat assumes JREPL.BAT is in a folder that is listed within your PATH environment variable. If you put JREPL.BAT in the same folder as encryptNames.bat, and then encrypt the files in that folder, then JREPL.BAT will be encrypted, and you will no longer be able to run encryptNames.bat!

How to read specific string in txt file by using windows batch?

This is the content of my .txt file
123:456
789:333
I'm trying to use findstr to read string and search for 789:333, but it only print fist line 123:456
As I know, use cut can fulfill my requirement in Linux.
In Windows, do we have any method where we can search for a string in a file by using a batch-script?
it is simple. using a for loop.
#echo off
for /F "delims=" %%a in ('findstr /I "789:333" somefile.txt') do echo %%a
you can learn a lot about batch file commands by simply opening a cmd.exe window and typing help
It describes briefly each command and once you find one that you think might work, like let's say for, then you simply do for /? which will show you help content which will make your life easy.

Batch: use multiple files with same extension as a single argument?

So I'm doing some texture converting, and thought I'd automate some of the process with batch, first half was done easy, now I'm kind of stuck on second half.
The process goes tga > ctex > bch
tga > ctex was easy since you can individually input and convert each file, so I used this batch script;
for %%f in (*.tga) do NW4C_TextureConverter.exe %%f --output=%%~nf.ctex --format=ETC1_A4 --etc_encoding=mediumimproved
However, this won't work from ctex to bch because I need all ctex files found to be used as a single input so that they all combine into a single bch, like so;
NW4C_h3dbincvtr -o=output.bch (ctext file1) (ctex file2) (ctex file3)...
What would be the easiest way to implement the first script so that instead of using each file individually I can append all files to the end of the second command?
Thanks for the suggestion, searching for something along those lines helped me find what I needed, for future reference the answer was found here and what I used was;
setlocal disableDelayedExpansion set "files=" for /r %%F in (*.ctex) do call set files=%%files%% "%%F" NW4C_h3dbincvtr -o=output.bch %files%
worked perfectly!

cmd batch recall commands history

I have a batch script that takes an url as argument and before doing the main operations of the script, It saves the url in a log file.
Is there a way to read the log file (when I execute it next time) and add the entries to the history so it can be used (by UP KEY) like a recall history ?
it isn't that hard, you need to make a log.txt holding all the data.
Use this to add something in it:
echo [action]>>log.txt
And this to read it:
for /f "tokens=* delims=" %%a in (a.txt) do echo %%a
by the way, this is in #echo off
A very similar thing is possible using For loops, Line counts, an Array containing the stored Urls retrieved from the file, and the Choice command within a Loop to Page through the array.
Here is an example

Windows cmd suggested input

I am attempting to write a .bat file that prompts the user for a file path before continuing. However, this is a script that I plan on running repeatedly on the same file, so it would save me a lot of time to not have to re-enter that path every time. I plan on saving the path to another file each time it's run. What I'm hoping i can do then is, when the prompt comes up, have the previous path pre-entered. That way I could either just hit enter, or backspace and change it to a new path. How would I go about pre-entering the text? Is it possible? Any feedback or suggestions are welcome.
for /f "usebackq delims=" %%a in ("c:\path to\wherever\your\file.is") do set "filepath=%%a"
set /p "filepath=Select path or just [Enter] for %filepath%"
echo select path was "%filepath%"
>"c:\path to\wherever\your\file.is" echo %filepath%
The point is that set /p leaves the target variable unmolested if the Enter key alone is used.
#ECHO OFF
IF EXIST %~dpn0.save.cmd (CALL %~dpn0.save.cmd)
SET /p "savedpath=Please specify file path or press Enter for default [%savedpath%] : "
ECHO SET savedpath=%savedpath%> %~dpn0.save.cmd
The beauty of this approach is that, if elsewhere in the script you decide that the preserved value should be forgotten, you just delete the .save.cmd file.
Years ago - when I used to work in command scripts everyday - we had examples where these types of values would come from a different section of the same script file, and the preserved values would simply be written back to the same file; however, I can't recall the details, and this separate-file approach will do the trick.

Resources