[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Reversing this code (getting UN-ASCII of the string)

Posted on 2008-01-26
6
Medium Priority
?
388 Views
Last Modified: 2012-08-13
This code reverses the string and gives me the ASCII of the string. Now I have the ASCII code , how can I get reverse the code and get the actuall string back again?
Dim test As String = "123456789012345"
 
        Dim lLen As Integer, lCtr As Integer
        Dim sChar As String
        Dim sAns As String = ""
 
        lLen = Len(test)
        For lCtr = lLen To 1 Step -1
            sChar = Chr(192 + Asc(Mid(test, lCtr, 1)))
            sAns = sAns & sChar
        Next
 
        TextBox1.Text = sAns

Open in new window

0
Comment
Question by:Camillia
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:thigger_uk
ID: 20752039
Your code doesn't give you the ASCII of the string (which would be a series of numbers), but a new string which is the original string reversed and with 192 added to the code of each character. For number characters as above (ASCII 48-57) this results in an output with codes in the range 240-249. You should be aware that inputting a string containing letters to your code will cause problems (as adding 192 to eg 'A'=65 gives a number outside the normal 0-255 ASCII range).

To reverse the code:



Dim sCode as String
sCode = TextBox1.Text
 
     Dim lLen As Integer, lCtr As Integer
        Dim sChar As String
        Dim sAns As String = ""
 
        lLen = Len(sCode)
        For lCtr = lLen To 1 Step -1
            sChar = Chr(192 + Asc(Mid(sCode, lCtr, 1)))
            sAns = sAns & sChar
        Next
 
Decoded version now held in sAns.

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 20752063
let me try
0
 
LVL 7

Author Comment

by:Camillia
ID: 20752073
No, I get this error : Procedure or call is not valid. I get it on sChar:

 Dim sCode As String
        sCode = sAns  ' this is where I encode it (in my code)
        lLen = Len(sCode)
        For lCtr = lLen To 1 Step -1
            sChar = Chr(192 + Asc(Mid(sCode, lCtr, 1)))  ' I get the error heree\
            sAns = sAns & sChar
        Next

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Accepted Solution

by:
thigger_uk earned 2000 total points
ID: 20753126
Sorry - mistake in my code (too much cut'n'paste)

Line 10 should read:
sChar = Chr(Asc(Mid(sCode, lCtr, 1)) - 192)

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 20753806
oh, let me try.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20754264
thanks, that worked
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question