Question:
How can I encrypt the source code of a batch file?
1970-01-01 00:00:00 UTC
How can I encrypt the source code of a batch file?
Six answers:
Shadow Wolf
2010-11-13 08:57:07 UTC
Various companies and people have been trying for years to develop an encrypted programming language. The short version is that even if you "encrypt" it, then it really only changes the form of the programming language. It would be kind of like writing a program in C, encrypting it and running the program as BASIC. All you end up doing is trading one kind of language for another.



The next best solution is the locked or self destructing embedded processors. While they have build in defenses to keep people from copying or tampering with the program, a determined individual or corporation with enough resources can still get the program. So really there is no sense in trying to hide a program except to perhaps limit what the average person can do.



One possible solution would be to literally encrypt the batch file. Your interpreter would then need to decrypt your batch file as it was running.. One of the first problems you would encounter is that you'd need to write a custom decrypting interpreter Next, either you'd need to embed the key or request the key from the user. An embedded key is no better than writing it on a post-it note and sticking it to the monitor. If you were trying to prevent the user from reading your code, then getting a key from the user is also a problem. A third solution would be to employ public key cryptography. However, the decrypt key is still embedded and easily obtained. The only thing this solution prevents is that the user can't create new batch files to work with your system. Lastly, unless you stored the entire decrypted script in memory, you'd be limited to stream scripts. Storing the batch file in memory decrypted is yet another weakness that would allow it to be copied. Streamed scripts could be decrypted using pipes, but that all by itself is an obvious weakness.



The most you can do is copyright your code. Simply adding a copyright notice is enough. Should you need to enforce the copyright, then it is generally a good idea to file. If it is really unique, you might want to invest in patenting it, but that route is generally madness unless it is something really useful.



Somehow I doubt your batch file is worth encrypting. Never saw a script or batch file that was. If you simply want to protect it from tampering, use a compiled language such as C to do the work. It won't protect your batch file from being copied or reproduced in another form since a compiled program is really just a machine language version of the higher level language program.



Don't let anyone fool you into believing it is more difficult to disassemble a machine language program. While there are problems and obstacles when disassembling things, the only real problem is it takes much more time and you need an individual who is experienced with it.. For most cases, it isn't economical to disassemble stuff. For a short batch file it would probably be faster to simply write a new program. For those who would argue against me, how do you thing anti-virus companies and others pick apart the latest worm or virus?



The most I ever put into my programs is a copyright notice. After all, I already know how to get around every protection scheme I've ever seen or tried to devise. I'm under no illusions that there are others just as skilled and some even more skilled than I am.



Shadow Wolf
2016-12-09 00:16:10 UTC
Batch File Encryption
?
2016-10-16 02:33:31 UTC
What scripting language are you utilising? i might think of of coming up a loop around your good judgment the place the contents are written into the document. for each loop, deliver the output to a variable consisting of log$x.txt the place $x gets incremented via a million every time. determine you shut the document if your language calls for you to close data that are opened.
Just Jess
2010-11-15 20:46:24 UTC
Encryption isn't the answer if you want code to be inaccessible to a user, but still want the user to be able to run it. The standard solution for what you'd like to do is a "server side protocol".



The way to set this up is to have a web server or other interface to your code that you have full control over. This is like the front door to your house. To stretch the analogy a little further, when a user comes up and knocks on the door, your batch file executes completely, and then displays the results to the user, without the user ever seeing the code. Everything happens behind closed doors, and the door doesn't open until your batch file is done running.



This is usually done with a web server, a scripting language, and a database.



You can just use your batch file as your script.



A popular web server is the apache server, which you can find here,



http://www.gossipcheck.com/mirrors/apache//httpd/binaries/win32/httpd-2.2.17-win32-x86-openssl-0.9.8o.msi



And provided your script is simple enough, you won't need a database.



You will need to set up a "cgi bin" and tell apache how to interpret batch files. If you want something that handles all the setup for you, instead of using batch files, use a scripting language like php,



http://windows.php.net/download/



And if you don't want to configure anything, you can use an "all in one" package, like xampp, here,



http://www.apachefriends.org/en/xampp-windows.html



If you DO want to encrypt things anyway, then here's how you do it:



-Encrypt something however you'd like to encrypt it

-Have it completely decrypt itself to a random temporary file

-Run that temp file

-Have the temp file destroy itself when it's done running



Even though a plain English copy of your script exists this way, there is no security difference between this and decrypting as you go.



The reason for this is that Windows is a signals-and-registry based OS. Any executable program you have is a set of instructions. On a windows machine, your set of instructions contains four things:

-Resources (things like pictures, sounds, movies, etc)

-Your "window class" (not a "class" in the normal programming class; think of it as the skeleton for your program)

-Calls to put info into and take info out of the registry (the registry is just the database that comes built-in to Windows)

-A signal function (a sub-program that runs when an event happens, for example, when you click a button or move the mouse over something)



All four of these things are visible to Windows, and thus to a clever user. So any user running your code can know anything about your code, without ever reading it.



The easy way to remember all of that is this: if it's running on my computer, it's mine. If it's running on your computer, it's yours.



If you want something kept secret, run it on your computer.
steve_loir
2010-11-13 07:52:50 UTC
A batch file is written in clear text. If you encrypt it then it cannot be executed.



If you don't want anyone to know how you wrote a program then use a compiled language like C+. Then once it is compiled it is very difficult to take apart.
2010-11-13 07:54:01 UTC
You can compile batch file into an EXE file. There are many utilities available on the net which can do it for you.



.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...