1.

Solve : Batch File Encryption.?

Answer»

I am sure when you read the title you thought this would be another "How do I encrypt my batch files?" thread. XP

I am not sure how to explain this, but I want to make a batch that pretty much does this;

Import text.
Change text.
Export text.

I do not fully understand the < and > commands quite yet, as I see no help for them in command prompt.
I know how to export something.

Echo Hi > C:\Test.txt

But I do not know how to use this to my advantage.

And I do not understand how to use the import currectly.
So...Lets say something along the lines of...

Make a text file that says Hi.
Import into my batch.
Change H to A
Change i to 9
Export
Now the txt says A9 instead of Hi.
Like,  somehow have the bat replace A's with B's, and B's with A's.  Or something like that.
If I could get how to make this, I could reverse it to decrypt the text as well.
But I am not exactly sure how to get this to work.
Of course,  I wouldnt use this as my primary way to Encrypt things. I am just trying to learn is all.
I already have a huge batch made up that will do this:

Work on startup, constantly close every application (Even taskmanager and Explorer) and ask for a password.  If the currect password is given, it will stop the process killing,  open explorer, and let you continue.
Just for fun and laughs really.






Also side question, how do I edit a txt file with cmd?  ASSUMING I know the line number, of course.
So lets say I wanted to change my password needed to continue my computer work;
The passwords are stored on line, 23, 28, and 45.
then go.
Xcopy Batch.bat Batch.txt
then edit batch.txt
Then use CALL to open up Batch2 (so Batch can be copied over). 
Then do:
Xcopy Batch.txt batch.bat
Then CALL again to go back to batch, DELETE batch.txt, then the password is changed.

I will use Third-Party programs if necessary.    (On either question)

RUNNING WindowsXP Media. SP2.Use a programming language eg Python or Perl, to do this.
Code: [Select]>>> print "hello".encode('rot13')
uryyb
the above generates rot13 of the word hello. Simple and just take few seconds. Of course, for full fledge encryption, use a well know algorithm such as AES or RSA using modules made for that such as PyCrypto. You can do similar things like this with Perl as well. Thanks for the reply.
But I want to make a batch file to Encrypt a text file, just to see if I can myself.
If I needed REAL encryption, or encryption that is pre-made,  I would have downloaded a different Encrypter like you said.

I want to make a batch that has a database (that I make of course)  that says like:
A=1
B=$
C=-
D=3 and so on and so on.

And and the same batch will replace, ABCD, with 1$-3.

Its just something I want to make myself.
Like my own little encryption system.

I just want to know if I can do it,  if so how?
Its for the pure fact if learning.  Like I said, if I wanted real encryption I could download something else like TrueCrypt or something, lol.the easiest way to do this type of "mapping" is by using a data structure called a dictionary or associative arrays.. a little example in Python
Code: [Select]>>> d={} # initialize associative array
>>> d["A"]="C"
>>> d["B"]="D"
>>> d["C"]="E"
>>> for character in ['A','B','C']:
...     print d[character]
...
C
D
E

cmd.exe doesn't support such data structures, so you would either go through character mapping one by one be using set and assignment each character with a  value and doing a lot of if/else checking , or completely dump batch and START to learn something more useful.Technically that isn't encryption, btw, it's actually called a cipher.

Not saying this to be a smartass, but rather because it might help refine your google searches on the subject Look at this:

set varname=%varname:A=!%
set varname=%varname:[email protected]%
set varname=%varname:C=#%

and so on and so fourth...XP Sorry ghost lol.   I learn whatever is entertaining for me.  Batch is VERY simple for the most part.
I mod games alot, going into it with a HEX editor,  trying to MEMORIZE things, etc.   
So going to batch to toy around for a while is simple enough that I can kinda relax on it for the most part and sometimes make something a little entertaining without having to put in too much thought.
I also know id need to make my own If/Else database of some kind.  I have no problem with that.  I acturally already thought I would have to.

BC:
Thanks,  I didnt even know that word existed lol,  maybe I can find something on google here in a sec after im done posting then.

Helpmeh:
I think I see what its doing there.
But how would I go about making batch load up C:\Test.txt (for example) to change the stuff inside it?
Like..

Load up Test.txt
Change number and letters.
Save Test.txtSo, you want something like this then?

echo off
setlocal enabledelayedexpansion
set filein=C:\test.txt
set fileout=C:\testout.txt
for /f "delims=" %%a in (%filein%) do (
     set origline=%%a
     rem Some characters require a ^ before them to prevent errors. I put it infront of all replacements
     rem just in case.
     set newline=!origline:a=^!
     set newline=!newline:b=^#!
     set newline=!newline:c=^$!
     rem ...
     echo !newline! >> !fileout!
)Perfect.
Exactly what I wanted. I didnt know you could use set commands with files.  XP Thanks again.
Real fast question though.
what does it mean when you use more then one % at a time? Quote from: Frozen2Dream on April 04, 2010, 04:34:53 PM

what does it mean when you use more then one % at a time?

Type FOR /? at the prompt.

Quote from: Salmon Trout on April 04, 2010, 05:01:17 PM
Type FOR /? at the prompt.
Please note, it will say %a, %i, etc. but that only applies to commands run from the command prompt, two % are for in batch files. Quote from: Helpmeh on April 04, 2010, 05:18:42 PM
Please note, it will say %a, %i, etc. but that only applies to commands run from the command prompt, two % are for in batch files.

It says:

Code: [Select]To use the FOR command in a batch program, specify %%variable instead of %variable.


Discussion

No Comment Found