Encrypting data for a batch file
Moderator: DosItHelp
-
- Posts: 21
- Joined: 23 Aug 2012 00:07
Encrypting data for a batch file
Ok, I know that there is always someone out there who can crack any kind of encryption, but this is to stop your average user/small time power user.
How can I encrypt a file, so that it's contents are not easily editable...
E.g. You can't just go into an exe file and edit away.
This is to store data for a batch file, that I don't particularly want users editing...
I'm considering just hexing the entire file, but that'd make it rather large...
How can I encrypt a file, so that it's contents are not easily editable...
E.g. You can't just go into an exe file and edit away.
This is to store data for a batch file, that I don't particularly want users editing...
I'm considering just hexing the entire file, but that'd make it rather large...
Re: Encrypting data for a batch file
keyboard1333 wrote:How can I encrypt a file, so that it's contents are not easily editable...
E.g. You can't just go into an exe file and edit away.
That would depend on how the data got into the .EXE file.
Re: Encrypting data for a batch file
You can use something as simple as ROT13 or change it ROT7 or whatever else takes your fancy.
http://en.wikipedia.org/wiki/ROT13
http://en.wikipedia.org/wiki/ROT13
-
- Posts: 21
- Joined: 23 Aug 2012 00:07
Re: Encrypting data for a batch file
Actually, I just thought of a better example -
The source of a .docx file is all gibberish?
How do they do that?
But thanks for your reply!!!
The source of a .docx file is all gibberish?
How do they do that?
But thanks for your reply!!!
Re: Encrypting data for a batch file
A .docx file is a ZIP file, with a different extension. So is a .JAR file.
If you have a specific task to solve then tell us the details.
However if you are just wondering about the insides of computer files - they aren't really on topic in a batch file forum.
If you have a specific task to solve then tell us the details.
However if you are just wondering about the insides of computer files - they aren't really on topic in a batch file forum.
-
- Posts: 21
- Joined: 23 Aug 2012 00:07
Re: Encrypting data for a batch file
It was more of a theory question than a practical problem.
I have had experiences before we're I've needed to store data, but been unable as it would be accessable to anybody on can edit a file...
Many software(s?), store their data in a way so that it is not easily editable from outside the application, and I was wondering how to do this.
I guess not just encrypting the data, but storing it in a way that is... I'm not sure how to say this?
I have had experiences before we're I've needed to store data, but been unable as it would be accessable to anybody on can edit a file...
Many software(s?), store their data in a way so that it is not easily editable from outside the application, and I was wondering how to do this.
I guess not just encrypting the data, but storing it in a way that is... I'm not sure how to say this?
Re: Encrypting data for a batch file
You encrypt the data with an algorithm and decrypt it to read it again.
A basic example is to use ROT-13 to encrypt a file and then use ROT-13 again to decrypt it.
This is the ROT-13 encryption of the text above - it's simple but it stops people reading it, who don't know about ROT-13.
Lbhe rapelcg gur qngn jvgu na nytbevguz naq qrpelcg vg gb ernq vg ntnva.
N onfvp rknzcyr vf gb hfr EBG-13 gb rapelcg n svyr naq gura hfr EBG-13 ntnva gb qrpelcg vg.
A basic example is to use ROT-13 to encrypt a file and then use ROT-13 again to decrypt it.
This is the ROT-13 encryption of the text above - it's simple but it stops people reading it, who don't know about ROT-13.
Lbhe rapelcg gur qngn jvgu na nytbevguz naq qrpelcg vg gb ernq vg ntnva.
N onfvp rknzcyr vf gb hfr EBG-13 gb rapelcg n svyr naq gura hfr EBG-13 ntnva gb qrpelcg vg.
Re: Encrypting data for a batch file
If you don't want people to edit your files then set the appropriate file permissions so they only have read access to that file.
Re: Encrypting data for a batch file
maybe you want encode, not encrypt.
encrypt should be hard in batch because is slow and have some limitations.
encrypt should be hard in batch because is slow and have some limitations.
-
- Posts: 21
- Joined: 23 Aug 2012 00:07
Re: Encrypting data for a batch file
Yes, that's what I'm looking for
Encode...
Any tips on that?
Encode...
Any tips on that?
Re: Encrypting data for a batch file
I think in this instance, encode and encrypt mean the same thing.
You are changing the input data in a known way, so you can obfuscate it, and also restore it to the original format.
You are changing the input data in a known way, so you can obfuscate it, and also restore it to the original format.
Re: Encrypting data for a batch file
foxidrive wrote:You encrypt the data with an algorithm and decrypt it to read it again.
A basic example is to use ROT-13 to encrypt a file and then use ROT-13 again to decrypt it.
This is the ROT-13 encryption of the text above - it's simple but it stops people reading it, who don't know about ROT-13.
Lbhe rapelcg gur qngn jvgu na nytbevguz naq qrpelcg vg gb ernq vg ntnva.
N onfvp rknzcyr vf gb hfr EBG-13 gb rapelcg n svyr naq gura hfr EBG-13 ntnva gb qrpelcg vg.
Your example is wrong! The first encripted word "Lbhe" is NOT the encription of "You" because it has one letter more. I think that if you post examples as simple as this one (or complex ones, for that matter) you must be sure that the example is right!
Below is a basic ROT-13 encription Batch program:
Code: Select all
@echo off
rem simple rot-13 conversion filter program
rem fvzcyr ebg-13 pbairefvba svygre cebtenz
setlocal enabledelayedexpansion
set letter=abcdefghijklmnopqrstuvwxyz
for /l %%a in (0,1,25) do (
set /a rot13=%%a+13
if !rot13! geq 26 set /a rot13-=26
for %%b in (!rot13!) do set rot13!letter:~%%a,1!=!letter:~%%b,1!
)
for /f "delims=" %%a in ('findstr "^"') do (
setlocal disabledelayedexpansion
set "line=%%a"
setlocal enabledelayedexpansion
set lastchar=0
for /l %%b in (9,-1,0) do (
set /a "lastchar|=1<<%%b"
for %%c in (!lastchar!) do if "!line:~%%c,1!" equ "" set /a "lastchar&=~1<<%%b"
)
set output=
for /l %%b in (0,1,!lastchar!) do (
set char=!line:~%%b,1!
if defined rot13!char! for %%c in (!char!) do set char=!rot13%%c!
set output=!output!!char!
)
echo !output!
endlocal & endlocal
)
Code: Select all
@rpub bss
erz fvzcyr ebg-13 pbairefvba svygre cebtenz
erz simple rot-13 conversion filter program
frgybpny ranoyrqrynlrqrkcnafvba
frg yrggre=nopqrstuvwxyzabcdefghijklm
sbe /y %%n va (0,1,25) qb (
frg /n ebg13=%%n+13
vs !ebg13! trd 26 frg /n ebg13-=26
sbe %%o va (!ebg13!) qb frg ebg13!yrggre:~%%n,1!=!yrggre:~%%o,1!
)
sbe /s "qryvzf=" %%n va ('svaqfge "^"') qb (
frgybpny qvfnoyrqrynlrqrkcnafvba
frg "yvar=%%n"
frgybpny ranoyrqrynlrqrkcnafvba
frg ynfgpune=0
sbe /y %%o va (9,-1,0) qb (
frg /n "ynfgpune|=1<<%%o"
sbe %%p va (!ynfgpune!) qb vs "!yvar:~%%p,1!" rdh "" frg /n "ynfgpune&=~1<<%%o"
)
frg bhgchg=
sbe /y %%o va (0,1,!ynfgpune!) qb (
frg pune=!yvar:~%%o,1!
vs qrsvarq ebg13!pune! sbe %%p va (!pune!) qb frg pune=!ebg13%%p!
frg bhgchg=!bhgchg!!pune!
)
rpub !bhgchg!
raqybpny & raqybpny
)
I hope it helps...
Antonio
Re: Encrypting data for a batch file
Nice Aacini
But I see at least one bug. Your use of a simple FOR will cause problems if text contains * or ?.
Also, I don't understand why your string length computation uses 9. 12 is required to support the maximum ~8191 line length.
Finally, your master loop is skipping empty lines, easily fixed with FINDSTR /N followed by search for *: and replace with nothing.
Nearly two years ago I published an efficient batch ROT13 routine: viewtopic.php?p=7028#p7028
After adding support for mixed case and fixing the issues noted above, your algorithm is ~20% faster than my old method
Here is my implementation of your algorithm:
Dave Benham
But I see at least one bug. Your use of a simple FOR will cause problems if text contains * or ?.
Also, I don't understand why your string length computation uses 9. 12 is required to support the maximum ~8191 line length.
Finally, your master loop is skipping empty lines, easily fixed with FINDSTR /N followed by search for *: and replace with nothing.
Nearly two years ago I published an efficient batch ROT13 routine: viewtopic.php?p=7028#p7028
After adding support for mixed case and fixing the issues noted above, your algorithm is ~20% faster than my old method
Here is my implementation of your algorithm:
Code: Select all
@echo off
:: simple rot-13 conversion filter program
setlocal disableDelayedExpansion
set lower=abcdefghijklmnopqrstuvwxyz
set upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
for /l %%a in (0,1,25) do (
set /a "rot13=(%%a+13)%%26"
setlocal enableDelayedExpansion
for %%b in (!rot13!) do for /f "tokens=1-4" %%A in (
"!lower:~%%a,1! !lower:~%%b,1! !upper:~%%a,1! !upper:~%%b,1!"
) do (
endlocal
set "lower%%A=%%B"
set "upper%%C=%%D"
)
)
for /f "delims=" %%a in ('findstr /n "^"') do (
set "line=%%a"
setlocal enableDelayedExpansion
set "line=!line:*:=!"
set output=
if defined line (
set /a len=0
for /l %%b in (12,-1,0) do (
set /a "len|=1<<%%b"
for %%c in (!len!) do if "!line:~%%c,1!" equ "" set /a "len&=~1<<%%b"
)
for /l %%b in (0,1,!len!) do (
set "char=!line:~%%b,1!"
if defined lower!char! for /f delims^=^ eol^= %%c in ("!char!") do (
if "!lower:%%c=%%c!" neq "!lower!" (
set "char=!upper%%c!"
) else set "char=!lower%%c!"
)
set "output=!output!!char!"
)
)
echo(!output!
endlocal
)
Dave Benham