Text String to Hashes (md5 – sha1 – sha256)

Covert Text String to Hashes (md5 – sha1 – sha256)

Title Text String to Hashes (md5 - sha1 - sha256) by xsukax

:: colors
SETLOCAL EnableExtensions DisableDelayedExpansion
for /F %%a in ('echo prompt $E ^| cmd') do (
  set "ESC=%%a"
SETLOCAL EnableDelayedExpansion

:: Hashes
set "plaintext=%~1"
set "file=%temp%\%~n0.tmp"
set md5=
set sha1=
set sha256=

if not defined plaintext set /P "plaintext="

if exist "%plaintext%" (
    set "file=%plaintext%"
) else for %%I in ("%file%") do if %%~zI equ 0 (
    <NUL >"%file%" set /P "=%plaintext%"

for /f "skip=1 delims=" %%I in ('certutil -hashfile "%file%" MD5') do (
    if not defined md5 set "md5=%%I"
for /f "skip=1 delims=" %%I in ('certutil -hashfile "%file%" SHA1') do (
    if not defined sha1 set "sha1=%%I"
for /f "skip=1 delims=" %%I in ('certutil -hashfile "%file%" SHA256') do (
    if not defined sha256 set "sha256=%%I"
2>NUL del "%temp%\%~n0.tmp"

echo Text       : %plaintext% >> results-history.txt
echo MD5 Hash   : %md5: =% >> results-history.txt
echo SHA1 Hash  : %sha1: =% >> results-history.txt
echo SHA256 Hash: %sha256: =% >> results-history.txt
echo ----------------------------------------------------------------------------- >> results-history.txt
echo MD5 Hash   : %ESC%[33m%md5: =%%ESC%[0m
echo SHA1 Hash  : %ESC%[33m%sha1: =%%ESC%[0m
echo SHA256 Hash: %ESC%[33m%sha256: =%%ESC%[0m
echo ------------
echo Show History
echo ------------
type results-history.txt

:: Choices
goto start
ECHO 1. Keep History.
ECHO 2. Clear History.
set choice=
set /p choice=Type Your Choice: 
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto keep
if '%choice%'=='2' goto clear
ECHO "%choice%" is not valid, try again
goto start
echo ---------------------------
echo You choose to keep History.
echo ---------------------------
goto end
del results-history.txt
echo ----------------
echo History Cleared.
echo ----------------
goto end

Leave a Reply

Your email address will not be published. Required fields are marked *