473,473 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

print question - character representation

hi!

i am calculating a digest of some data (using hmac) and printing it to a
cookie. the problem is the hash may contain special characters. when these
are printed they get converted to \<number> representation.
later when i receive the cookie i recalculate the hmac and do a comparison
which returns false because of the conversion when writing to a cookie

q - how do i stop the conversion from happening? if i cant then how can i
convert the hmac i recalculate on receiving the cookie to the same
representation as the one printed

thanks

cheers

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
2 1647
Ajay <ab******@mail.usyd.edu.au> writes:
i am calculating a digest of some data (using hmac) and printing it to a
cookie. the problem is the hash may contain special characters. when these
are printed they get converted to \<number> representation.
later when i receive the cookie i recalculate the hmac and do a comparison
which returns false because of the conversion when writing to a cookie
q - how do i stop the conversion from happening?


Use the hexdigest() method instead of digest() to avoid non-printable
characters. See the hmac library documentation for details.

--
Brian Gough

Network Theory Ltd,
Publishing the Python Manuals --- http://www.network-theory.co.uk/python/
Jul 18 '05 #2
Ajay <ab******@mail.usyd.edu.au> wrote in message news:<ma**************************************@pyt hon.org>...
hi!

i am calculating a digest of some data (using hmac) and printing it to a
cookie. the problem is the hash may contain special characters. when these
are printed they get converted to \<number> representation.
later when i receive the cookie i recalculate the hmac and do a comparison
which returns false because of the conversion when writing to a cookie

q - how do i stop the conversion from happening? if i cant then how can i
convert the hmac i recalculate on receiving the cookie to the same
representation as the one printed

thanks

cheers


One way is to use a binary to ascii conversion - like the binascii module.

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rim | last post by:
Hi, >>> print '%x' % 54 36 >>> print '%b' % 54 Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: unsupported format character 'b' (0x62) at index 1 >>>
12
by: neutrino | last post by:
Greetings to the Python gurus, I have a binary file and wish to see the "raw" content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string...
3
by: RHNewBie | last post by:
Hello, I have the following string "ADDASSFölhandel ADFS" which is referred to by a variable whose type declaration is "usigned char *extendedasciistring". When I print using %s I see the...
21
by: g.kanaka.raju | last post by:
Hi, I'm looking for a way to print ® in a C program. Could any of you help me out? Regards, Raju
2
by: Mori | last post by:
Hi, Can someone supply a code example of displaying a string with a fractional part, say 5 and 7 16ths. I cannot find an example of how to use the Encoding object (if that is what you use). ...
8
by: Gas | last post by:
Hi, I am wondering how can I representation some of the specical characters in C#? (for example, we use vbKeyTab for Tab and vbCrLf for line feed in VB) Also is there any character to ASCII...
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
13
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.