-
Jan 6th, 2013, 01:06 PM
#1
Thread Starter
PowerPoster
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?
-
Jan 6th, 2013, 01:17 PM
#2
Re: Reversing this code?
try this:
Code:
MsgBox(String.Concat(encrypted.Select(Function(c) Chr(Asc(c) - 13)).ToArray))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 6th, 2013, 01:21 PM
#3
Thread Starter
PowerPoster
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!
-
Jan 6th, 2013, 01:36 PM
#4
Thread Starter
PowerPoster
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.
-
Jan 7th, 2013, 11:43 AM
#5
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
-
Jan 7th, 2013, 12:08 PM
#6
Thread Starter
PowerPoster
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
-
Jan 7th, 2013, 01:45 PM
#7
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
-
Jan 7th, 2013, 01:50 PM
#8
Thread Starter
PowerPoster
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
-
Jan 7th, 2013, 02:14 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|