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

Author Topic: Find and Replace (Encryption)  (Read 8129 times)

0 Members and 1 Guest are viewing this topic.

Jacob

    Topic Starter


    Hopeful

    Thanked: 1
    • Experience: Expert
    • OS: Windows XP
    Find and Replace (Encryption)
    « on: November 27, 2008, 09:56:43 AM »
    I am in the process of making some kind of encrypter and decrypter, for this I need to find and replace letters, for instance "a" will be replaced with "$".

    I have already searched around but the topics I have seen are inconclusive, thanks to anybody who offers any kind of support.

    I am looking for help on how to find and replace strings in a text file.
    « Last Edit: November 27, 2008, 10:37:47 AM by Jacob »

    Prince_



      Beginner

      Thanked: 5
      Re: Find and Replace (Encryption)
      « Reply #1 on: November 27, 2008, 10:03:00 AM »
      Quote
      for instance "a" will be replaced with "$".
      what if there is $ in the original codes?

      Jacob

        Topic Starter


        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Re: Find and Replace (Encryption)
        « Reply #2 on: November 27, 2008, 10:08:14 AM »
        Quote
        for instance "a" will be replaced with "$".
        what if there is $ in the original codes?
        It's a text file. It is only meant to contain text. Then if that happens I will replace "a" with "\$1" it was simply an example, to help the person who answers my question.

        Besides, then "$" will be replaced with "^&".
        « Last Edit: November 27, 2008, 10:22:24 AM by Jacob »

        Prince_



          Beginner

          Thanked: 5
          Re: Find and Replace (Encryption)
          « Reply #3 on: November 27, 2008, 10:29:26 AM »
          i think you may replace each other in the 26 chars.
          e.g.

          a->b
          b->c
          c->d
          ...
          z->a

          Jacob

            Topic Starter


            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            Re: Find and Replace (Encryption)
            « Reply #4 on: November 27, 2008, 10:31:46 AM »
            You don't get it do you.
            I will be replacing only text but I can encrypt that into any symbol.
            Code: [Select]
            a -> !!
            b -> *!
            c -> (!
            d -> ^!
            e -> :!
            as an example, and to decrypt:
            Code: [Select]
            !! -> a
            *! -> b
            (! -> c
            ^! -> d
            :! -> e
            I would prefer it if you no longer posted if you can provide no help on my topic.

            Prince_



              Beginner

              Thanked: 5
              Re: Find and Replace (Encryption)
              « Reply #5 on: November 27, 2008, 10:35:10 AM »
              srr, but what help do you need? i dun follow you...

              Dias de verano

              • Guest
              Re: Find and Replace (Encryption)
              « Reply #6 on: November 27, 2008, 10:37:09 AM »
              To replace text in a string, you can use the set command thus

              set string=%string:a=b%

              where a and b are strings

              Code: [Select]
              C:\>set string=bab

              C:\>set string=%string:a=o%

              C:\>echo %string%
              bob

              C:\>set string=%string:o=eee%

              C:\>echo %string%
              beeeb

              C:\>set string=%string:e=^!%

              C:\>echo %string%
              b!!!b

              Jacob

                Topic Starter


                Hopeful

                Thanked: 1
                • Experience: Expert
                • OS: Windows XP
                Re: Find and Replace (Encryption)
                « Reply #7 on: November 27, 2008, 10:38:18 AM »
                To replace text in a string, you can use the set command thus

                set string=%string:a=b%

                where a and b are strings

                Code: [Select]
                C:\>set string=bab

                C:\>set string=%string:a=o%

                C:\>echo %string%
                bob

                C:\>set string=%string:o=eee%

                C:\>echo %string%
                beeeb

                C:\>set string=%string:e=^!%

                C:\>echo %string%
                b!!!b


                Thanks you very much, problem solved.
                But how would i get this to run through everything in a text file rather than just a variable.

                Dias de verano

                • Guest
                Re: Find and Replace (Encryption)
                « Reply #8 on: November 27, 2008, 10:42:25 AM »
                But how would i get this to run through everything in a text file rather than just a variable.

                An interesting exercise for you, Jacob.

                You can read the text file line by line into a variable using FOR, as I am sure you must know by now. Inside the loop you can do all the string replacements in the line of text, and then write it out to a new file.

                Prince_



                  Beginner

                  Thanked: 5
                  Re: Find and Replace (Encryption)
                  « Reply #9 on: November 27, 2008, 10:43:31 AM »
                  you dun know how to replace a char in a string? ...
                  then i have to tell you that there are lots of limitations when the cmd.exe dealing with the replacement.
                  i advise that you give up your complex idea about the encryption, juz use my method.

                  Jacob

                    Topic Starter


                    Hopeful

                    Thanked: 1
                    • Experience: Expert
                    • OS: Windows XP
                    Re: Find and Replace (Encryption)
                    « Reply #10 on: November 27, 2008, 10:45:49 AM »
                    But how would i get this to run through everything in a text file rather than just a variable.

                    An interesting exercise for you, Jacob.

                    You can read the text file line by line into a variable using FOR, as I am sure you must know by now. Inside the loop you can do all the string replacements in the line of text, and then write it out to a new file.


                    Sorry, I do not know how to set a line as a variable.

                    Dias de verano

                    • Guest
                    Re: Find and Replace (Encryption)
                    « Reply #11 on: November 27, 2008, 10:46:32 AM »
                    you dun know how to replace a char in a string? ...
                    then i have to tell you that there are lots of limitations when the cmd.exe dealing with the replacement.
                    i advise that you give up your complex idea about the encryption, juz use my method.

                    What method? I don't see any method. Just an idea. Both your idea and Jacob's are equivalent. The classic simple substitution cypher.

                    Dias de verano

                    • Guest
                    Re: Find and Replace (Encryption)
                    « Reply #12 on: November 27, 2008, 10:49:23 AM »
                    But how would i get this to run through everything in a text file rather than just a variable.

                    An interesting exercise for you, Jacob.

                    You can read the text file line by line into a variable using FOR, as I am sure you must know by now. Inside the loop you can do all the string replacements in the line of text, and then write it out to a new file.


                    Sorry, I do not know how to set a line as a variable.

                    You did on Oct 24th

                    http://www.computerhope.com/forum/index.php/topic,69075.msg451057.html#msg451057

                    Jacob

                      Topic Starter


                      Hopeful

                      Thanked: 1
                      • Experience: Expert
                      • OS: Windows XP
                      Re: Find and Replace (Encryption)
                      « Reply #13 on: November 27, 2008, 10:51:41 AM »
                      Code: [Select]
                      If in doubt, delims== will always grab the whole line (which is what you want.) Note I used set /a because the 2nd line of the output file
                      from wmic contains a TAB character after the percentage number, which I wanted to remove

                      So, I did, thanks, and sorry.  :)

                      Prince_



                        Beginner

                        Thanked: 5
                        Re: Find and Replace (Encryption)
                        « Reply #14 on: November 27, 2008, 10:52:33 AM »
                        Quote
                        Sorry, I do not know how to set a line as a variable.

                        ...

                        Code: [Select]
                        C:\>type test.txt
                        hello
                        world
                        C:\>for /f %a in (test.txt) do @set line=%a

                        C:\>echo %line%
                        world