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 8130 times)

0 Members and 1 Guest are viewing this topic.

Prince_



    Beginner

    Thanked: 5
    Re: Find and Replace (Encryption)
    « Reply #15 on: November 27, 2008, 10:56:57 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.


    what i wanna say is that the Jacob's idea of replacement is too complex to realize, for him especially

    Jacob

      Topic Starter


      Hopeful

      Thanked: 1
      • Experience: Expert
      • OS: Windows XP
      Re: Find and Replace (Encryption)
      « Reply #16 on: November 27, 2008, 11:04:38 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.


      what i wanna say is that the Jacob's idea of replacement is too complex to realize, for him especially

      Sorry, suddenly because I do not know how to replace strings in a text file, I do not understand the idea of encryption? One, cannot know everything.

      Dias de verano

      • Guest
      Re: Find and Replace (Encryption)
      « Reply #17 on: November 27, 2008, 11:06:27 AM »
      what i wanna say is that the Jacob's idea of replacement is too complex to realize, for him especially

      What I want to say is that your unhelpful and snooty attitude is not appropriate for this forum.

      Jacob, you seem to want to replace each letter of the alphabet with a pair of characters. This is all very well, but you should realise that certain character pairs have special meaning in cmd scripts, particularly if the first character of the pair is a caret (^). For example ^! is replaced by cmd with !

      Jacob

        Topic Starter


        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Re: Find and Replace (Encryption)
        « Reply #18 on: November 27, 2008, 11:08:44 AM »
        what i wanna say is that the Jacob's idea of replacement is too complex to realize, for him especially

        What I want to say is that your unhelpful and snooty attitude is not appropriate for this forum.

        Jacob, you seem to want to replace each letter of the alphabet with a pair of characters. This is all very well, but you should realise that certain character pairs have special meaning in cmd scripts, particularly if the first character of the pair is a caret (^). For example ^! is replaced by cmd with !

        Yes, I am currently stuck with the following, I have dinner now, so is it okay if I leave you to ponder around with this?
        Code: [Select]
        @echo off
        set FileName=text.txt
        for /f "skip=0 delims==" %%A in ('type %FileName%') do (
        set string=%%A
        set string=%string:a=o%
        echo %string%>!%FileName%
        )
        pause >nul
        « Last Edit: November 27, 2008, 11:19:02 AM by Jacob »

        Prince_



          Beginner

          Thanked: 5
          Re: Find and Replace (Encryption)
          « Reply #19 on: November 27, 2008, 11:09:33 AM »
          In actual fact, i've done the work about one year before ,which you're doing now. I know how hard it is while replacing some chars.

          Jacob

            Topic Starter


            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            Re: Find and Replace (Encryption)
            « Reply #20 on: November 27, 2008, 11:17:56 AM »
            In actual fact, i've done the work about one year before ,which you're doing now. I know how hard it is while replacing some chars.
            I very much doubt that, or you would of been able to help me, like I said before, I'd prefer it if you do not post on my thread anymore.

            Prince_



              Beginner

              Thanked: 5
              Re: Find and Replace (Encryption)
              « Reply #21 on: November 27, 2008, 11:20:45 AM »
              Quote
              What I want to say is that your unhelpful and snooty attitude is not appropriate for this forum.

              unhelpful? snooty?
              im trying my best to help him, and if i said something wrong when you think im snooty, i make an apology

              Dias de verano

              • Guest
              Re: Find and Replace (Encryption)
              « Reply #22 on: November 27, 2008, 11:32:04 AM »

              Yes, I am currently stuck with the following, I have dinner now, so is it okay if I leave you to ponder around with this?
              Code: [Select]
              @echo off
              set FileName=text.txt
              for /f "skip=0 delims==" %%A in ('type %FileName%') do (
              set string=%%A
              set string=%string:a=o%
              echo %string%>!%FileName%
                                ^
                           
              )
              pause >nul

              Code: [Select]
              echo %string%>!%FileName%
                            ^
                            |
                            |
                   Why is this here?

              You need to learn about delayed expansion. Variables in a parenthetical expression such as a FOR loop or a block IF structure are not updated because of the way cmd expands variables at runtime. You need to use a special technique...

              1. Place this line before the code

              setlocal enabledelayedexpansion

              2. Use ! signs instead of % signs inside the loop for the variables you wish to change as the loop runs.

              Code: [Select]
              @echo off
              setlocal enabledelayedexpansion
              set FileName=text.txt
              for /f "skip=0 delims==" %%A in ('type %FileName%') do (
              set string=%%A
              set string=!string:a=o!
              echo !string!>%FileName%
              )
              pause >nul

              You do know that your code will only work if the file %FileName% contains exactly one line?

              Jacob

                Topic Starter


                Hopeful

                Thanked: 1
                • Experience: Expert
                • OS: Windows XP
                Re: Find and Replace (Encryption)
                « Reply #23 on: November 27, 2008, 11:45:11 AM »
                Thank you, but I get:
                Code: [Select]
                delims==" was unexpected at this timeand the
                Code: [Select]
                echo %string%>!%FileName%was there to differentiate a crypted file and a non crypted file.

                And i am aware that this will only work for one line, but i am planning on looping it much like this:
                Code: [Select]
                :loop
                find /c " " data\accounts\%AccName%\bank.txt>data\temp\linecount\%AccName%.txt
                for /f "tokens=1,2,3 delims= " %%A in ('type data\temp\linecount\%AccName%.txt ^| find "BANK.TXT:"') do (
                    set count=%%C
                    )
                set /a id=%id%+1
                for /f "tokens=1,2,3 delims=:" %%A in ('type data\accounts\%AccName%\bank.txt ^| find "=%id%="') do (
                    set itemidno=%%B
                set itemq=%%C
                    )
                for /f "tokens=1,2,3 delims=:" %%A in ('type data\item\items.txt ^| find "ID=%itemidno%="') do (
                    set itemn=%%B
                set itemp=%%C
                    )
                set /a itemw=%itemp%*%itemq%
                echo     %itemq% x %itemn% [%itemw%]
                if %ID% NEQ %count% (
                goto loop
                )

                Dias de verano

                • Guest
                Re: Find and Replace (Encryption)
                « Reply #24 on: November 27, 2008, 11:53:36 AM »
                Thank you, but I get:
                Code: [Select]
                delims==" was unexpected at this time

                This is because skip=0 is not allowed. You must use a value of 1 or more. If you are skipping 0 lines, omit the skip=N part altogether.

                diablo416



                  Hopeful
                  • Experience: Beginner
                  • OS: Unknown
                  Re: Find and Replace (Encryption)
                  « Reply #25 on: November 27, 2008, 12:42:37 PM »

                  ive tryed something similar to this, i gave up on it because there was already third party software that would do this from cmd.exe,  the problem i came across in the end is the unknown amount of charachters in the current line,

                  i thought of another way to do this, but i could never make it work as i dident understand setlocal enabledelayedexpansion well enough, something like this
                  just as an example

                  @echo off
                  set cn=0
                  setlocal enabledelayedexpansion
                  for /f "Tokens=1*" %%a in (file) do (
                         call set line=%%a%%b
                         if "!%line:~!%cn%!,1%!"=="w" set file.%!cn!%=u
                         call set /a cn=%!cn!%+1
                  )


                  that wont work

                  diablo416



                    Hopeful
                    • Experience: Beginner
                    • OS: Unknown
                    Re: Find and Replace (Encryption)
                    « Reply #26 on: November 27, 2008, 12:49:46 PM »
                    you might also consider, having every charachter on a new line.. for example


                    @echo off
                    :TOP
                    set /p encr=-
                    set mes=%mes%%encr:~0,1%
                    echo.&echo %encr:~0,1%>>FILE
                    CLS&Echo %mes%&Pause>nul & goto TOP


                    as a way of writting the message to be encrypted then just using if statements

                    Dias de verano

                    • Guest
                    Re: Find and Replace (Encryption)
                    « Reply #27 on: November 27, 2008, 12:59:25 PM »
                    You can get the length of any string by echoing it to a temp file and then using FOR to get the file size, and finally subtracting 2 from that (for the cr and lf at the end)

                    Code: [Select]
                    @echo off
                    set string=123456789
                    echo %string%>%temp%\getlength.txt
                    for %%L in (%temp%\getlength.txt) do set /a slen=%%~zL
                    set /a slen-=2
                    echo length %slen%

                    Note: no space between the variable name and the > symbol




                    devcom



                      Apprentice

                      Thanked: 37
                      Re: Find and Replace (Encryption)
                      « Reply #28 on: November 27, 2008, 01:10:06 PM »
                      i've made sth like encrypting program based on random generated key's
                      ex of usage:

                      Code: [Select]
                      Password: computerhope
                      Key: 6CLgj9e1rtH4pFuNXDoA7mzqVY82WskB0I3
                      Generated: 402YDtFz0t
                      Code: [Select]
                      Password: computerhope
                      Key: Z19Es6WG2xFa4yrHctmI5D3UqoV7jNB80L
                      Generated: a07otxy30x

                      decrypt work well too
                      Download: Choice.exe

                      Dias de verano

                      • Guest
                      Re: Find and Replace (Encryption)
                      « Reply #29 on: November 27, 2008, 01:19:31 PM »
                      Code: [Select]
                      @echo off
                      setlocal enabledelayedexpansion
                      set string=Mary had a little lamb

                      REM Get string length
                      echo %string%>%temp%\getlength.txt
                      for %%L in (%temp%\getlength.txt) do set /a slen=%%~zL
                      set /a slen-=2
                      echo String is %string%
                      echo String length is  %slen%


                      REM show each character in the line
                      for /L %%C in (1,1,%slen%) do (
                      set /a n=%%C-1
                              call set char=%%string:~!n!,1%%
                              echo Character %%C   is  !char!
                      )