Results 1 to 9 of 9

Thread: Reversing this code?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Reversing this code?

    looking at some legacy code, this is trying to "encrypt" an input string. Not the best way:

    Code:
    rawData=lcase(rawData)
    encrypted=""
    for iIdx=1 to len(rawData)
    	encrypted=encrypted & chr(asc(mid(rawData,iIdx,1))+13)
    next
    C#:

    Code:
    rawData= Convert.ToString(rawData).ToLower();
    encrypted= "";
    for (var iIdx = 1; iIdx <= rawData.Length; iIdx++)
    {
    	encrypted= encrypted + (char)(Convert.ToInt32(rawData[iIdx - 1]) + 13);
    }

    I am wondering if there is a way to reverse the generated string in encrypted so I can get back the original input?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Reversing this code?

    try this:

    Code:
    MsgBox(String.Concat(encrypted.Select(Function(c) Chr(Asc(c) - 13)).ToArray))

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Reversing this code?

    Thanks. seems to work for the first handpicked set.
    almost have it done another way too but reversing the for loop. Didn't think it was that simple but.. it was!

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Reversing this code?

    hmm. ok on a few of them did not quite work. it gives me square type characters and not sure what the original string was.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Reversing this code?

    Some characters can't be displayed. If you don't know what the original string was, do you know how it was created? It would certainly be possible to create a string that contained non-display characters, which may be the situation.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Reversing this code?

    I don't know how it was created. All I know is that the way it was created was using the code that was posted in my original post

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Reversing this code?

    Then there is no reason to assume that the characters in the original string were restricted to just those found in the visible character set, so ANY byte value is technically available, including the set of characters above 127.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Reversing this code?

    yes but what im getting at is what character could those be?
    I want to be able to decrypt it into a readable format, then encrypt it again to make sure that the encrypted before and after are correct

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Reversing this code?

    Technically, you are only looking at byte values. Every byte value equates to a character, but not all characters are displayable (how would you display backspace?). It is entirely possible that you CAN'T decrypt some character strings into a readable format. What do you want to do then? Would it be acceptable to just show the byte code values? How about the byte code values and the characters as long as the characters are visible?
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width