473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Where I can find a url decode algorithm

Hi everybody!

I have such a problem. I wrote a web portal on C++, but I found one big "-" in that script: C++ is not supporting url decoding(I mean data sent by HMTL forms).

As a developer I can solve this problem in many ways, but the easier would be, if I understand how to convert ASCII Hex (%D3 for example) to a symbol it represents.

As I guess, there must be a certain algorythm how it was encoded, and the same how it may be decoded.
As we all know there is a certain way to convert digits to binary(I mean if you have 57 for example, then:
32 16 8 4 2 1
57/32= 1 , 25/16=1, 9/8=1 , 1/4 = 0, 1/2 = 0 , 1/1 = 1, so binary is 111001.
Is there some kind of formula to convert ASCII Hex to ASCII, or easier to say how to decode URL content?
Thanks to everyone.
May 17 '07 #1
5 5478
Ganon11
3,652 Expert 2GB
If I understand it correctly, a hex number in HTML with the form %XY is a character encoded in Hexidecimal, with number value XY. To find the ASCII version, you should only have to convert to decimal. The value (in decimal) of a hex number XY is X * 16 + Y.

So, when parsing the imformation, you can look for a '%' symbol. If you find one, you have come across a hex character that needs to be decoded. Discard the '%' and retrieve the XY numbver, convert to decimal using the above formula, and then cast it to a character in order to decode.
May 17 '07 #2
Pardon, I've been mistaken... It's a little bit different, first comes numder, then a char: %3A%3D%5B%5D.

each char is represented is 3 chars.

so, if i need to convert %3A to char, I need to 3x16 + A?

And the last question: how I convert decimal to char?
http://spacelogic.eu/cgi-bin/spacelogic.cgi - here is a link to script. I'm sorry it's in russian, but it works the same way.
May 17 '07 #3
Ganon11
3,652 Expert 2GB
OK, the process still holds. Remember, in hexidecimal, a letter is basically a digit. So all you have to do is get each digit individually - if a digit is a number (0-9), you can multiple normally. If it's a letter (A-F), convert it to its equivalent (A = 10, B = 11, etc), and then proceed with the multiplication.

As for the decimal number to a character, just make a char variable and initialize it to a number:

Expand|Select|Wrap|Line Numbers
  1. char myChar = 90;
May 17 '07 #4
Thanks a lot! It works fine. A REALLY HUGE THANKS!!!
May 17 '07 #5
By the way, do you know how russian symbols are represented in ASCII?
Somehow they all have negative values(in HEX it's %E0 and in ASCII it's -48).

PS. I found an answer. All russian symbols comes over 127 limit, and as a result, char value comes as: 127 - font_value, and here comes "-" symbol.

So huge thanks for help! I even did't hope to get answers so quickly.
May 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed...
9
by: Krishna Sagiraju | last post by:
Hai, I gotta decode a barcode from an image ( ppm, bmp, or jpg). I realize the first milestone would be to recognize a barcode with in the image: I took a small window (say 80X80 pixels) and if...
0
by: richasaraf | last post by:
Hello everyone, Please HELP !!!!! I'm facing problem in converting CASE statements into DECODE. As i have PL/SQL 8i, so it does not handle CASE statements. Please send me the solutions . Then...
5
by: Draw | last post by:
Hi All, Just a thought, about the find() algorithm in the C++ STL. I read that the find algorithm can take a range of iterators. If it does not find the element it is looking for in that range...
2
by: rsd | last post by:
Hi, I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. To do that I need to run http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py script, the idea behind the...
10
by: Christian Chrismann | last post by:
Hi, I've a question on the STL find algorithm: My code: int main( void ) { vector< ClassA* myVector; ClassA *ptrElement1 = ...;
2
by: hojjatnikan | last post by:
please help me this code 62EH&5gx0wiqoQFw is this name ( Belux) but i dont know how convert it i dont know the algorithm of this code plead help me
7
by: php.developer2007 | last post by:
I want to know to decode sha1 encoded url into normal url. Example www.example.com/<sha1 code>/index1.htm I want this to www.example.com/index1.htm
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.