Cryptage des Fichiers Batch
J'essaie donc de crypter un mot de passe que mon entreprise utilise pour putty ssh. Le problème est que le PW utilise des caractères spéciaux et que le chiffrement / déchiffrement im utilisant ne fonctionne pas avec des caractères spéciaux depuis son extension retardée. À l'aide!
@echo off
mode con lines=11
title Crypt
:begin
endlocal
setlocal enabledelayedexpansion
call :header
set map=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890^^!
set /p "command=Encrypt or Decrypt? (e/d):"
if "%command%"=="e" goto ENC
if "%command%"=="d" goto DEC
:MenuError
call :header
echo: ERROR: !command! is an invalid option.
pause
goto begin
:ENC
call :header
set /p "filename=Enter the File name you wish to save the Text under (Eg. Text):"
:ENCpwd
call :header
set /p "text=Enter the text you wish to encrypt (20 char limit, Characters can include [a-z] [A-Z] [0-9] [space]):"
call :header
echo:Encrypting...
:ENC2
set num2=0
set c=
set /a num1=%num1%+1
set /a num3=%num3%+1
if %num3%==21 goto ENC4
for /l %%x in (0,1,19) do set /a inc=%%x+1&if %num3%==!inc! set "c=!text:~%%x,1!"
:ENC3
if %num2%==0 set L=
for /l %%x in (0,1,65) do set /a inc=%%x+1&if %num2%==!inc! set "L=!map:~%%x,1!"
set e%num1%=
if "%c%"=="%L%" set e%num1%=%num2%
if "%c%"==" " set e%num1%=0
set /a num2=%num2%+1
if defined e%num1% goto ENC2
goto ENC3
:ENC4.1
set /a Rnum=%Rnum%-1
:ENC4
set /a Rnum=%Rnum%+1
set rcheck=%random:~0,4%
set /a rcheck2=%rcheck%+63
if %rcheck% LSS 1063 goto ENC4.1
if %rcheck2% GTR 9999 goto ENC4.1
set r%Rnum%=%rcheck%
if defined r20 goto ENC5
goto ENC4
:ENC5
for /l %%x in (1,1,20) do set /a e%%x=!e%%x!+!r%%x!
for /l %%x in (1,1,20) do (
set "estr=!estr!!e%%x!"
set "rstr=!rstr!!r%%x!"
)
echo:!estr!>"%filename%.pwd"
echo:!rstr!>"%filename%.key"
:ENC6
call :header
echo:Encrypting complete^^!
ping -n 3 -i 1 127.0.0.1>nul
goto begin
:DEC
call :header
echo: NOTE: The encrypted file (*.pwd) and Key file (*.key) must be under the same name (Eg. Password.pwd and Password.key)
echo: AND in the same directory as this batch file.
echo:
set /p "filename=Enter the File name the Encrypted Text was saved under (Eg. Text):"
call :header
if not exist "%filename%.pwd" goto ERRpwd
if not exist "%filename%.key" goto ERRkey
goto DEC2
:ERRpwd
echo: ERROR: !filename!.pwd was not found
pause
goto DEC
:ERRkey
echo: ERROR: !filename!.key was not found
pause
goto DEC
:DEC2
call :header
echo:Decrypting...
set /p "key= "<"%filename%.key"
set /p "pwd= "<"%filename%.pwd"
for /l %%x in (0,4,76) do (
set /a counter+=1
set "k!counter!=!key:~%%x,4!"
set "e!counter!=!pwd:~%%x,4!"
)
:DEC3
set num2=0
set t=
set /a num+=1
if %num%==21 goto DEC5
for /l %%x in (1,1,20) do if %num%==%%x set /a "t=!e%%x!-!k%%x!"
:DEC4
if %num2%==0 set L=blank
for /l %%x in (0,1,65) do set /a inc=%%x+1&if %num2%==!inc! set "L=!map:~%%x,1!"
set t%num%=
if %t%==%num2% set "t%num%=%L%"
if defined t%num% goto DEC3
set /a num2+=1
goto DEC4
:DEC5
for /l %%x in (1,1,20) do if "!t%%x!"=="blank" set "t%%x= "
for /l %%x in (1,1,20) do set "tstr=!tstr!!t%%x!"
call :header
echo:Decrypting complete^^!
Set new=%tstr%
ECHO !tstr!
pause
goto begin
:header
cls
echo:________________________________________________________________________________
echo: Text Encryptor/Decryptor by maniacal
echo:________________________________________________________________________________
exit/b