Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File Encryption.  (Read 10566 times)

0 Members and 1 Guest are viewing this topic.

Frozen2Dream

    Topic Starter


    Greenhorn

    Batch File Encryption.
    « on: April 04, 2010, 01:24:11 AM »
    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.

    ghostdog74



      Specialist

      Thanked: 27
      Re: Batch File Encryption.
      « Reply #1 on: April 04, 2010, 02:04:47 AM »
      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.

      Frozen2Dream

        Topic Starter


        Greenhorn

        Re: Batch File Encryption.
        « Reply #2 on: April 04, 2010, 03:02:17 AM »
        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.

        ghostdog74



          Specialist

          Thanked: 27
          Re: Batch File Encryption.
          « Reply #3 on: April 04, 2010, 06:27:29 AM »
          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.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Batch File Encryption.
          « Reply #4 on: April 04, 2010, 08:52:36 AM »
          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 :)
          I was trying to dereference Null Pointers before it was cool.

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: Batch File Encryption.
          « Reply #5 on: April 04, 2010, 10:12:28 AM »
          Look at this:

          set varname=%varname:A=!%
          set varname=%varname:B=@%
          set varname=%varname:C=#%

          and so on and so fourth...
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          Frozen2Dream

            Topic Starter


            Greenhorn

            Re: Batch File Encryption.
            « Reply #6 on: April 04, 2010, 02:38:52 PM »
            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.txt

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: Batch File Encryption.
            « Reply #7 on: April 04, 2010, 02:59:02 PM »
            So, 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!
            )
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            Frozen2Dream

              Topic Starter


              Greenhorn

              Re: Batch File Encryption.
              « Reply #8 on: April 04, 2010, 04:34:53 PM »
              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?

              Salmon Trout

              • Guest
              Re: Batch File Encryption.
              « Reply #9 on: April 04, 2010, 05:01:17 PM »
              what does it mean when you use more then one % at a time?

              Type FOR /? at the prompt.


              Helpmeh



                Guru

              • Roar.
              • Thanked: 123
                • Yes
                • Yes
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 8
              Re: Batch File Encryption.
              « Reply #10 on: April 04, 2010, 05:18:42 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.
              Where's MagicSpeed?
              Quote from: 'matt'
              He's playing a game called IRL. Great graphics, *censored* gameplay.

              Salmon Trout

              • Guest
              Re: Batch File Encryption.
              « Reply #11 on: April 05, 2010, 12:43:52 AM »
              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.