473,395 Members | 1,762 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.

Bit of a unicode ish

Hi
Having a bit of an ish with unicode.
Basically, I've discovered an encryption library on planetsourcecode that
does exactly what I want - it encrypts a string using a fairly (more than
just XOR) sophisticated method, using the functions in advapi32.lib, and can
decrypt it to get the same string back. It's not some unix hybrid that only
works with files or anything, so it seems good. And I tested it, and it does
seem to get the right string back.

However, I'm having a bit of an ish using printf on the returned value (the
encrypted data).
Does the console have an ish with printing garbage characters on the screen?
The code was something like this:
_TCHAR* origdata = "the data";
_TCHAR encrypted[255];
_TCHAR returndata[255];
printf(_T("The original data is \"%s\"\n"), origdata);
DoTheEncryption(origdata, encrypted, ...);
printf(_T("The encrypted data is \"%s\"\n"), encrypted);
DoTheDecryption(encrypted, returndata, ...);
printf(_T("The decrypted data is \"%s\"\n"), decyrpted);

And the output is something like
The original data is "the data"
The encrypted data is "Öûê┼!]The decyrpted data is "the data"

What's baffling is no matter what it thinks of my encrypted string - it
doesn't even respect my linefeed.

Any ideas?
I looked in the memory editor and the unicode string just looks like one
byte random, one byte zero, one byte random, one byte zero, etc...
Nov 17 '05 #1
4 1136
Why are you using printf with Unicode? You need to use wprintf, or the
generic text-mapping routine _tprintf which maps to printf in non-Unicode
builds and wprintf in Unicode builds.
You'd also need to put your string literal of origdata inside a _T()
declaration, but I guess this was just an example and not in the real code.
So something like:

_TCHAR* origdata = _T("the data");
_TCHAR encrypted[255];
_TCHAR returndata[255];
_tprintf(_T("The original data is \"%s\"\n"), origdata);
DoTheEncryption(origdata, encrypted, ...);
_tprintf(_T("The encrypted data is \"%s\"\n"), encrypted);
DoTheDecryption(encrypted, returndata, ...);
_tprintf(_T("The decrypted data is \"%s\"\n"), decyrpted);
Nov 17 '05 #2
Yes it IS that.
Sorry, I did use _tprintf..
Answer as if I'd put that.

"Simon Trew" wrote:
Why are you using printf with Unicode? You need to use wprintf, or the
generic text-mapping routine _tprintf which maps to printf in non-Unicode
builds and wprintf in Unicode builds.
You'd also need to put your string literal of origdata inside a _T()
declaration, but I guess this was just an example and not in the real code.
So something like:

_TCHAR* origdata = _T("the data");
_TCHAR encrypted[255];
_TCHAR returndata[255];
_tprintf(_T("The original data is \"%s\"\n"), origdata);
DoTheEncryption(origdata, encrypted, ...);
_tprintf(_T("The encrypted data is \"%s\"\n"), encrypted);
DoTheDecryption(encrypted, returndata, ...);
_tprintf(_T("The decrypted data is \"%s\"\n"), decyrpted);

Nov 17 '05 #3
> Any ideas?
I looked in the memory editor and the unicode string just looks like one
byte random, one byte zero, one byte random, one byte zero, etc...

There is no guarantee that encrypted data is printable.
You can have control characters, anything.
The custom is to dump it hex (for screen, email, etc.) or to write it a
file opened in binary mode.
--
Mihai
-------------------------
Replace _year_ with _ to get the real email
Nov 17 '05 #4
Brilliant, that's what I hoped.
I wanted to make sure somebody else thought the same thing to make sure I'm
not going *completely* insane.
"Mihai N." wrote:
Any ideas?
I looked in the memory editor and the unicode string just looks like one
byte random, one byte zero, one byte random, one byte zero, etc...

There is no guarantee that encrypted data is printable.
You can have control characters, anything.
The custom is to dump it hex (for screen, email, etc.) or to write it a
file opened in binary mode.
--
Mihai
-------------------------
Replace _year_ with _ to get the real email

Nov 17 '05 #5

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

Similar topics

3
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
8
by: Bill Eldridge | last post by:
I'm trying to grab a document off the Web and toss it into a MySQL database, but I keep running into the various encoding problems with Unicode (that aren't a problem for me with GB2312, BIG 5,...
8
by: Francis Girard | last post by:
Hi, For the first time in my programmer life, I have to take care of character encoding. I have a question about the BOM marks. If I understand well, into the UTF-8 unicode binary...
48
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
2
by: Neil Schemenauer | last post by:
python-dev@python.org.] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is...
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
6
by: Jeff | last post by:
Hi - I'm setting up a streamreader in a VB.NET app to read a text file and display its contents in a multiline textbox. If I set it up with System.Text.Encoding.Unicode, it reads a unicode...
13
by: Tomás | last post by:
Let's start off with: class Nation { public: virtual const char* GetName() const = 0; } class Norway : public Nation { public: virtual const char* GetName() const
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.