SHARE
TWEET

Encrypt-Decrypt files using CMD (Batch)

Imthedude025 Apr 27th, 2018 (edited) 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. ::Encrypt-Decrypt files using CMD                            ::
  3. ::Created by RU$$ [http://russdev.mooo.com/]                 ::
  4. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  5. @ECHO OFF
  6. TITLE Encrypt-Decrypt files using CMD
  7. setlocal enabledelayedexpansion
  8. SET BASE=-
  9. SET DIR=-
  10. SET file=-
  11.  
  12. If exist 7z.exe (GOTO :EXISTS1) else (GOTO :NOTEXISTS)
  13.  
  14. :EXISTS1
  15. If exist 7z.dll (GOTO :EXISTS) else (GOTO :NOTEXISTS)
  16.  
  17. :NOTEXISTS
  18. cls
  19.  
  20. Echo You do not have the needed 7z files in your dirrectory.
  21. Echo.
  22.  
  23. SET INPUT=
  24. SET /P INPUT= Do you wish to download them from GitHub? (Y/N):
  25.  
  26. IF /I '%INPUT%'=='Y' GOTO :DOWNLOAD
  27. IF /I '%INPUT%'=='y' GOTO :DOWNLOAD
  28. IF /I '%INPUT%'=='N' GOTO :CANCLED
  29. IF /I '%INPUT%'=='n' GOTO :CANCLED
  30.  
  31. goto :NOTEXISTS
  32.  
  33. :CANCLED
  34. cls
  35.  
  36. Echo ERROR: You need to download the needed files. Now exiting.
  37. Echo.
  38. pause.
  39. exit
  40.  
  41. :DOWNLOAD
  42. Echo STATUS: Now downloading the 7z directory files..
  43.  
  44. SET URL=http://7z-basefiles.webredirect.org/7z.zip
  45. bitsadmin /transfer mydownloadjob /download /priority normal ^ %URL% %~dp0\x.zip
  46.  
  47. Echo STATUS: Extracting files..
  48. powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%~dp0x.zip', '%~dp0'); }"
  49. del /Q x.zip
  50.  
  51. cls
  52. Echo STATUS: File(s) have downloaded successfully!
  53. Echo.
  54. Pause.
  55. GOTO :EXISTS
  56.  
  57. ::EXISTS
  58. :EXISTS
  59. cls
  60.  
  61. Echo Welcome to the Encrypt/Decrypt Menu!
  62. Echo 1. Encrypt an file
  63. Echo 2. Decrypt an file
  64. Echo 3. Exit (Delete 7z)
  65. Echo.
  66.  
  67. SET INPUT=
  68. SET /P INPUT= Please select an option:
  69.  
  70. IF /I '%INPUT%'=='1' GOTO :ENCRYPT
  71. IF /I '%INPUT%'=='2' GOTO :DECRYPT
  72. IF /I '%INPUT%'=='3' GOTO :EXIT
  73.  
  74. goto :EXISTS
  75.  
  76. ::ENCRYPT
  77. :ENCRYPT
  78.  
  79. .>> ListFile.txt
  80.  
  81. :START
  82. cls
  83.  
  84. Echo Select a base to bind. (Must include extension)
  85. Echo 1. Back to menu
  86. Echo.
  87. SET /p BASE=File Name:
  88.  
  89. IF /I '%BASE%'=='1' GOTO :EXISTS
  90. If exist %BASE% (GOTO :ZIP) else (GOTO :ERROR1)
  91.  
  92. :ERROR1
  93. cls
  94.  
  95. Echo ERROR: File not found!
  96. Echo.
  97.  
  98. Pause.
  99. GOTO :START
  100.  
  101. :ZIP
  102. ::Display
  103. cls
  104.  
  105. echo ============================================================
  106. echo Current List:
  107. echo ============================================================
  108. for /f "tokens=*" %%a in ('type ListFile.txt') do (
  109. set line=%%a
  110. echo !line! )
  111. echo ============================================================
  112. echo 1. Complete list
  113. echo 2. Delete List
  114. echo 3. Back to menu
  115. echo.
  116.  
  117. Echo Select files you wish to add to the zip. (Must include extension)
  118. Set /p DIR=File Name:
  119.  
  120. IF /I '%DIR%'=='1' GOTO :COMPLETE
  121. IF /I '%DIR%'=='2' GOTO :DELST
  122. IF /I '%DIR%'=='3' GOTO :MNU
  123.  
  124. If exist %DIR% (GOTO :CHECK) else (GOTO :ERROR2)
  125.  
  126. :CHECK
  127. Echo %DIR% >> ListFile.txt
  128. goto :ZIP
  129.  
  130. :DELST
  131. cls
  132. DEL ListFile.txt
  133. .>> ListFile.txt
  134. cls
  135.  
  136. Echo STATUS: List was deleted!
  137. Echo.
  138.  
  139. Pause.
  140. GOTO :ZIP
  141.  
  142. :ERROR2
  143. cls
  144.  
  145. Echo ERROR: File not found!
  146. Echo.
  147.  
  148. Pause.
  149. GOTO :ZIP
  150.  
  151. :COMPLETE
  152. cls
  153. Echo Now compressing your ZIP..
  154.  
  155. 7z a -tzip OUT.zip @ListFile.txt
  156. cls
  157. Echo Compression sucessful.
  158. Echo.
  159.  
  160. Pause.
  161. GOTO :NAME
  162.  
  163. :NAME
  164. cls
  165.  
  166. Echo Create a name for your output file. (Must include extension)
  167. Set /p FNAME=File Name:
  168.  
  169. GOTO :CRYPT
  170.  
  171. :CRYPT
  172. cls
  173. Echo Now encrypting %BASE%...
  174. copy /b %BASE% + OUT.zip "%FNAME%"
  175.  
  176. cls
  177. Echo Process complete! File has been encrypted. Returning to menu.
  178. Echo.
  179. pause.
  180. GOTO :MNU
  181.  
  182. :MNU
  183. DEL OUT.zip
  184. DEL ListFile.txt
  185.  
  186. GOTO :EXISTS
  187.  
  188. ::DECRYPT
  189. :DECRYPT
  190. cls
  191.  
  192. Echo Select the name of the file you with to extract. (Must include extension)
  193. Echo 1. Go to menu
  194. Echo.
  195. set /p file=File Name:
  196.  
  197. IF /I '%file%'=='1' GOTO :EXISTS
  198. If exist %file% (GOTO :LOCT) else (GOTO :NOTEXISTS1)
  199.  
  200. :NOTEXISTS1
  201. cls
  202.  
  203. Echo ERROR: File not found!
  204. Echo.
  205.  
  206. Pause.
  207. GOTO :DECRYPT
  208.  
  209. :LOCT
  210. %~dp07z.exe e -y %file% -o%temp%\Extracted\%file%
  211.  
  212. cls
  213. cd %temp%\Extracted\%file%
  214. echo ============================================================
  215. echo FILES IN ZIP:
  216. echo ============================================================
  217. echo.
  218. dir /b /a-d
  219. echo.
  220. echo ============================================================
  221. echo END OF FILE.
  222. echo ============================================================
  223. echo.
  224.  
  225. cd %~dp0
  226.  
  227. ::CMenu
  228. SET INPUT=
  229. SET /P INPUT= Do you wish to extract these files? (Y/N):
  230.  
  231. IF /I '%INPUT%'=='Y' GOTO :CONFIRMEDEX
  232. IF /I '%INPUT%'=='y' GOTO :CONFIRMEDEX
  233. IF /I '%INPUT%'=='N' GOTO :OPTCANCLED
  234. IF /I '%INPUT%'=='n' GOTO :OPTCANCLED
  235.  
  236. goto :LOCT
  237.  
  238. :OPTCANCLED
  239. cls
  240. RMDIR /s /q %temp%\Extracted
  241.  
  242. Echo Operation cancled! Returning to menu.
  243. Echo.
  244. Pause.
  245. GOTO :EXISTS
  246.  
  247. :CONFIRMEDEX
  248. RMDIR /s /q %temp%\Extracted
  249.  
  250. Echo STATUS: Now extracting encrypted files!
  251. %~dp07z.exe e -y %file% -o%~dp0Extracted
  252.  
  253. cls
  254. Echo STATUS: Files have been sucessfuly extracted to %~dp0Extracted
  255. Echo.
  256. pause.
  257.  
  258. GOTO :EXISTS
  259.  
  260. :EXIT
  261. Echo Exiting batch, Cleaning up files..
  262.  
  263. cd %~dp0
  264. Del /Q 7z.dll
  265. Del /Q 7z.exe
  266.  
  267. exit
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top