-
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?
-
Re: Reversing this code?
try this:
Code:
MsgBox(String.Concat(encrypted.Select(Function(c) Chr(Asc(c) - 13)).ToArray))
-
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!
-
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.
-
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.
-
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 :)
-
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.
-
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
-
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?