how do I add encryption from one batch file into another?

March 5, 2019 at 12:57:44
Specs: Windows 10
So I have a batch file that encrypts text and another batch file that is a chat program. How do I add the encryption program to the code for the chat program?

See More: how do I add encryption from one batch file into another?

Report •

#1
March 5, 2019 at 14:16:09
depends, a little info of which .bat does what when.

example code from both .bat files (or all of it, pastebin link if more than 50 lines of code)

also don't expect a response from me for the next 10 hours, it's pretty much midnight here in the netherlands

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@13-15-15-28 1T 3000MHz@1.42v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#2
March 5, 2019 at 18:38:48
the encryption program opens a window in which you type text and it then encrypts it, the messaging program opens a window and prompts you to type a username and sends any message you type to another file that receives it.

Report •

#3
March 5, 2019 at 18:41:41
I copied and pasted the code from this website and made the minor change of deleting the goto website portion of it.. http://forum.imgburn.com/index.php?...

message edited by N3cr0ph1l0us


Report •

Related Solutions

#4
March 6, 2019 at 00:57:52
ok, so this can be done in 2 ways (probably more actually)

1. call the encryption.bat and give it the variables it needs (so encryption.bat needs to be modified) from within the chat.bat, however as the this will pretty much launch encryption.bat as a completely separate program, making it hard to send the encrypted string/variables back to chat.bat.

With hard i mean encryption.bat has to save the variables to a file and chat.bat has to read it again, whichh i would rather not do as it creates an extra point of possible failure.

2. copy and paste the encryption.bat code (modified) into chat.bat and call the :label where encryption.bat starts. So basically i need to add 4 lines to encryption.bat and 2 to chat.bat

I'm just missing chat.bat to work with ;)

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@13-15-15-28 1T 3000MHz@1.42v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#5
March 6, 2019 at 01:06:29
forgot to mention, you didnt ask but, should i add the decrypter to the chat.bat aswell or are you going to do this yourself or can i add this function aswell?

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@13-15-15-28 1T 3000MHz@1.42v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#6
March 6, 2019 at 14:16:53
i already have a decryption program that goes along with the encryption one


This is the code for the chat program:
@echo off
color 0b
title Chat Messenger
echo Hi, welcome to the chat program!
echo.
set /p username=Enter Your Name:
echo %username% has joined! >> join.dat

:message
set /p message=Say:
goto send

:send
echo %username%: %message% (%time%)>> log.dat
goto message


Report •

#7
March 6, 2019 at 14:18:55
And this is the code for the file that receives the messages

@echo off

color 0a

:read

cls

type join.dat

echo.

type log.dat

echo.

timeout /t 10

goto :read


Report •

#8
March 7, 2019 at 01:58:17
im putting both enrypter+chat.bat into 1 file (chat.bat) & decrypter & receiver in 1 file (receiver.bat)

but I need to re-write quite a lot of code, so this may take some time

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@13-15-15-28 1T 3000MHz@1.42v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#9
March 7, 2019 at 02:59:08
currently working on receiver+decrypter.bat in 1

are you going to use this on a local network, from a network share?

anyways new chat.bat(includes encrypter.bat):


@echo off&color 0b&title Chat Messenger&setlocal enabledelayedexpansion
Pushd "%~dp0"
:start
cls
echo Hi, welcome to the chat program!
echo.
set /p "username=Enter Your Name:"
if "!username!"=="" goto start
:message
set message=
set /p "message=Say:"
if "!message!"=="" goto message
call :encrypt "!message!"
echo (%time%) - !username!:!EncryptOut!>>log.dat
goto message
:encrypt
(set CHAR[a]=UDFM45) & (set CHAR[b]=H21DGF) & (set CHAR[c]=FDH56D) & (set CHAR[d]=FGS546) & (set CHAR[e]=JUK4JH)
(set CHAR[f]=ERG54S) & (set CHAR[g]=T5H4FD) & (set CHAR[h]=RG641G) & (set CHAR[i]=RG4F4D) & (set CHAR[j]=RT56F6)
(set CHAR[k]=VCBC3B) & (set CHAR[l]=F8G9GF) & (set CHAR[m]=FD4CJS) & (set CHAR[n]=G423FG) & (set CHAR[o]=F45GC2)
(set CHAR[p]=TH5DF5) & (set CHAR[q]=CV4F6R) & (set CHAR[r]=XF64TS) & (set CHAR[s]=X78DGT) & (set CHAR[t]=TH74SJ)
(set CHAR[u]=BCX6DF) & (set CHAR[v]=FG65SD) & (set CHAR[w]=4KL45D) & (set CHAR[x]=GFH3F2) & (set CHAR[y]=GH56GF)
(set CHAR[z]=45T1FG) & (set CHAR[1]=D4G23D) & (set CHAR[2]=GB56FG) & (set CHAR[3]=SF45GF) & (set CHAR[4]=P4FF12)
(set CHAR[5]=F6DFG1) & (set CHAR[6]=56FG4G) & (set CHAR[7]=USGFDG) & (set CHAR[8]=FKHFDG) & (set CHAR[9]=IFGJH6)
(set CHAR[0]=87H8G7) & (set CHAR[@]=G25GHF) & (set CHAR[#]=45FGFH) & (set CHAR[$]=75FG45) & (set CHAR[*]=54GDH5)
(set CHAR[(]=45F465) & (set CHAR[.]=HG56FG) & (set CHAR[,]=DF56H4) & (set CHAR[-]=F5JHFH) & (set CHAR[ ]=SGF4HF)
(set CHAR[\]=45GH45) & (set CHAR[/]=56H45G)
set "Encrypt=%~1"
set "EncryptOut="
call :strlenmain "!message!"
set cnt=0
:loop
set/a cnt+=1
set "char=!Encrypt:~0,1!"
set "Encrypt=!Encrypt:~1!"
set "EncryptOut=%EncryptOut%!CHAR[%char%]!"
if !cnt! LSS !ans! goto loop
exit/b
:strlenmain
set ans=0
set "string=%~1"
call :strlen ans string
exit/b
:strlen
set l=0
set "s=!%~2!#"
for %%P in (512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set/a "l+=%%P"
set "s=!s:~%%P!"
)
)
set "%~1=%l%"
exit /b

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded

message edited by hidde663


Report •

#10
March 7, 2019 at 03:32:32
when i enter this in chat.bat i get;

Hi, welcome to the chat program

Enter Your Name:Hidde
Say:test
Saytest123

receiver has a chatoutput of:

Users:
Hidde

Chat:
(12:24:19.99) - Hidde: TH74SJJUK4JHX78DGTTH74SJ
(12:24:27.25) - Hidde: TH74SJJUK4JHX78DGTTH74SJD4G23DGB56FGSF45GF

which now has to be decrypted again

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#11
March 7, 2019 at 03:38:46
I will try to store chatlog.dat on the local machine and add a function to remove the log upon closing receiver

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#12
March 7, 2019 at 06:51:57
Thanks for all the help btw

Report •

#13
March 7, 2019 at 07:11:59
edit: receiver.bat done (does no longer save any plaintext decrypted chat anywhere, at the cost of more cpu time):

@echo off
color 0a
title Receiver
setlocal enabledelayedexpansion
pushd "%~dp0"
if not exist "log.dat" echo.>log.dat
set loop=0
for /l %%A in () do (
cls
echo Chat:
for /f "tokens=1-4,* delims=:" %%a in (log.dat) do (
call :decrypt "%%d"
echo %%a:%%b:%%c:!decryptOut!
)
echo.
timeout 5 /NOBREAK >nul
set\a loop+=1
if !loop!==18 set loop=0&del log.dat
)
:decrypt
(set CHAR[UDFM45]=a) & (set CHAR[H21DGF]=b) & (set CHAR[FDH56D]=c) & (set CHAR[FGS546]=d) & (set CHAR[JUK4JH]=e)
(set CHAR[ERG54S]=f) & (set CHAR[T5H4FD]=g) & (set CHAR[RG641G]=h) & (set CHAR[RG4F4D]=i) & (set CHAR[RT56F6]=j)
(set CHAR[VCBC3B]=k) & (set CHAR[F8G9GF]=l) & (set CHAR[FD4CJS]=m) & (set CHAR[G423FG]=n) & (set CHAR[F45GC2]=o)
(set CHAR[TH5DF5]=p) & (set CHAR[CV4F6R]=q) & (set CHAR[XF64TS]=r) & (set CHAR[X78DGT]=s) & (set CHAR[TH74SJ]=t)
(set CHAR[BCX6DF]=u) & (set CHAR[FG65SD]=v) & (set CHAR[4KL45D]=w) & (set CHAR[GFH3F2]=x) & (set CHAR[GH56GF]=y)
(set CHAR[45T1FG]=z) & (set CHAR[D4G23D]=1) & (set CHAR[GB56FG]=2) & (set CHAR[sF45GF]=3) & (set CHAR[P4FF12]=4)
(set CHAR[F6DFG1]=5) & (set CHAR[56FG4G]=6) & (set CHAR[USGFDG]=7) & (set CHAR[FKHFDG]=8) & (set CHAR[IFGJH6]=9)
(set CHAR[87H8G7]=0) & (set CHAR[G25GHF]=@) & (set CHAR[45FGFH]=#) & (set CHAR[75FG45]=$) & (set CHAR[54GDH5]=*)
(set CHAR[45F465]=() & (set CHAR[HG56FG]=.) & (set CHAR[DF56H4]=,) & (set CHAR[F5JHFH]=-) & (set CHAR[SGF4HF]= )
(set CHAR[45GH45]=\) & (set CHAR[56H45G]=/)
set "decrypt=%~1"
set "decryptOut="
call :strlenmain !decrypt!
set cnt=0
:loop
set/a cnt+=1
set "char=!decrypt:~0,6!"
set "decrypt=!decrypt:~6!"
set "decryptOut=%decryptOut%!CHAR[%char%]!"
if !cnt! LSS !ans! goto loop
exit/b
:strlenmain
set ans=0
set "string=%~1"
call :strlen ans string
exit/b
:strlen
set l=0
set "s=!%~2!#"
for %%P in (512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set/a "l+=%%P"
set "s=!s:~%%P!"
)
)
set/a "%~1=%l%/6"
exit/b

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded

message edited by hidde663


Report •

#14
March 7, 2019 at 07:57:41
updated both chat.bat and receiver.bat to cleanup chat every 18*10 seconds(to lower loading times per screen refresh), showing active users is not really doable for me without it becoming glitched.

i also fixed not being able to use spaces in between words.

o yeah and btw max string lenght is 85 characters, after that weird s--- happens.

other than that, i will try to make a single client, so no more 2 screens, shouldn't be that hard to do.
so check back next week or so

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded

message edited by hidde663


Report •

#15
March 7, 2019 at 08:13:48
you can read the contents of log.dat, but it's all encoded ^_^

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.395v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded


Report •

#16
March 8, 2019 at 05:14:20
Thank you for all of your help.I will test it out and see if it works.

Report •

#17
March 20, 2019 at 05:41:39
here is the combined single .bat, which does everything the above 2 .bat's do, but in a single window.

place chatter.bat in a networkdrive/shared folder and start the .bat form there, with a shortcut placed on the desktop, should work too.


anyways this is chatter.bat:

::chatter.bat a basic chat program, to be placed in a shared folder/network drive.
::chatter.bat provides partial end to end encryption (only the sentence that is typed gets encrypted, not the username or timestamp)
::
@echo off&title Chatter&setlocal enabledelayedexpansion
Pushd "%~dp0"
:settings
set refresh=120
set interval=3
:start
cls
echo Hi, welcome to the chat program!
echo.
set /p "username=Enter Your Name(not entering anything will use your windows name):"
if "!username!"=="" goto start
:receiver
set timeleft=%refresh%
for /l %%A in () do (
if not exist "log.dat" echo.>log.dat
cls
echo Chat ^(Refresh in !timeleft! seconds^):
set/a timeleft-=%interval%
if "!timeleft!"=="0" (
for /f "tokens=4,5 delims=M " %%1 in ('dir/A-D /-c ^| find "log.dat"') do if %%1 GEQ 2048 (
echo.>log.dat
set timeleft=%refresh%
)
)
for /f "tokens=1-4,* delims=:" %%a in (log.dat) do (
call :decrypt "%%d"
echo %%a:%%b:%%c:!decryptOut!
)
echo.
echo Press any key to start typing . . .
choice /c ²abcdefghijklmnopqrstuwvxyz0123456789 /n /t %interval% /d ² >nul
if not "!errorlevel!"=="1" call :message
)
exit/b
:message
set message=
set /p "message=Say:"
if "!message!"=="" exit/b
call :encrypt "!message!"
echo (%time%) - !username!:!EncryptOut!>>log.dat
exit/b
:encrypt
set crypt=encrypt
(set CHAR[a]=UDFM45) & (set CHAR[b]=H21DGF) & (set CHAR[c]=FDH56D) & (set CHAR[d]=FGS546) & (set CHAR[e]=JUK4JH)
(set CHAR[f]=ERG54S) & (set CHAR[g]=T5H4FD) & (set CHAR[h]=RG641G) & (set CHAR[i]=RG4F4D) & (set CHAR[j]=RT56F6)
(set CHAR[k]=VCBC3B) & (set CHAR[l]=F8G9GF) & (set CHAR[m]=FD4CJS) & (set CHAR[n]=G423FG) & (set CHAR[o]=F45GC2)
(set CHAR[p]=TH5DF5) & (set CHAR[q]=CV4F6R) & (set CHAR[r]=XF64TS) & (set CHAR[s]=X78DGT) & (set CHAR[t]=TH74SJ)
(set CHAR[u]=BCX6DF) & (set CHAR[v]=FG65SD) & (set CHAR[w]=4KL45D) & (set CHAR[x]=GFH3F2) & (set CHAR[y]=GH56GF)
(set CHAR[z]=45T1FG) & (set CHAR[1]=D4G23D) & (set CHAR[2]=GB56FG) & (set CHAR[3]=SF45GF) & (set CHAR[4]=P4FF12)
(set CHAR[5]=F6DFG1) & (set CHAR[6]=56FG4G) & (set CHAR[7]=USGFDG) & (set CHAR[8]=FKHFDG) & (set CHAR[9]=IFGJH6)
(set CHAR[0]=87H8G7) & (set CHAR[@]=G25GHF) & (set CHAR[#]=45FGFH) & (set CHAR[$]=75FG45) & (set CHAR[*]=54GDH5)
(set CHAR[(]=45F465) & (set CHAR[.]=HG56FG) & (set CHAR[,]=DF56H4) & (set CHAR[-]=F5JHFH) & (set CHAR[ ]=SGF4HF)
(set CHAR[\]=45GH45) & (set CHAR[/]=56H45G) & (set CHAR[:]=JSC9GF) & (set CHAR[^)]=45F461) & (set CHAR[[]=FOJDRL)
(set CHAR[]]=N9DLUF) & (set CHAR[!]=0EMMM6)
set "Encrypt=%~1"
set "EncryptOut="
call :strlenmain "%~1"
set cnt=0
:encryptloop
set/a cnt+=1
set "char=!Encrypt:~0,1!"
set "Encrypt=!Encrypt:~1!"
set "EncryptOut=%EncryptOut%!CHAR[%char%]!"
if !cnt! LSS !ans! goto encryptloop
exit/b
:decrypt
set crypt=decrypt
(set CHAR[UDFM45]=a) & (set CHAR[H21DGF]=b) & (set CHAR[FDH56D]=c) & (set CHAR[FGS546]=d) & (set CHAR[JUK4JH]=e)
(set CHAR[ERG54S]=f) & (set CHAR[T5H4FD]=g) & (set CHAR[RG641G]=h) & (set CHAR[RG4F4D]=i) & (set CHAR[RT56F6]=j)
(set CHAR[VCBC3B]=k) & (set CHAR[F8G9GF]=l) & (set CHAR[FD4CJS]=m) & (set CHAR[G423FG]=n) & (set CHAR[F45GC2]=o)
(set CHAR[TH5DF5]=p) & (set CHAR[CV4F6R]=q) & (set CHAR[XF64TS]=r) & (set CHAR[X78DGT]=s) & (set CHAR[TH74SJ]=t)
(set CHAR[BCX6DF]=u) & (set CHAR[FG65SD]=v) & (set CHAR[4KL45D]=w) & (set CHAR[GFH3F2]=x) & (set CHAR[GH56GF]=y)
(set CHAR[45T1FG]=z) & (set CHAR[D4G23D]=1) & (set CHAR[GB56FG]=2) & (set CHAR[SF45GF]=3) & (set CHAR[P4FF12]=4)
(set CHAR[F6DFG1]=5) & (set CHAR[56FG4G]=6) & (set CHAR[USGFDG]=7) & (set CHAR[FKHFDG]=8) & (set CHAR[IFGJH6]=9)
(set CHAR[87H8G7]=0) & (set CHAR[G25GHF]=@) & (set CHAR[45FGFH]=#) & (set CHAR[75FG45]=$) & (set CHAR[54GDH5]=*)
(set CHAR[45F465]=() & (set CHAR[HG56FG]=.) & (set CHAR[DF56H4]=,) & (set CHAR[F5JHFH]=-) & (set CHAR[SGF4HF]= )
(set CHAR[45GH45]=\) & (set CHAR[56H45G]=/) & (set CHAR[JSC9GF]=:) & (set CHAR[45F461]=^)) & (set CHAR[FOJDRL]=[)
(set CHAR[N9DLUF]=]) & (set CHAR[0EMMM6]=!!)
set "decrypt=%~1"
set "decryptOut="
call :strlenmain "!decrypt!"
set cnt=0
:decryptloop
set/a cnt+=1
set "char=!decrypt:~0,6!"
set "decrypt=!decrypt:~6!"
set "decryptOut=%decryptOut%!CHAR[%char%]!"
if !cnt! LSS !ans! goto :decryptloop
exit/b
:strlenmain
set ans=0
set "string=%~1"
call :strlen ans string
exit/b
:strlen
set l=0
set "s=!%~2!#"
for %%P in (512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set/a "l+=%%P"
set "s=!s:~%%P!"
)
)
if "!crypt!"=="encrypt" (
set "%~1=%l%"
) else (
set/a "%~1=%l%/6"
)
exit/b

i5-6600K[delid]@4.7GHz/4.4GHz cache/@1.392v | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2260MHz@1500MHz timings BiosModded

message edited by hidde663


Report •

Ask Question