473,569 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encryption for a log and Unicode Characters...? Yikes!

Hello everyone... This may sound really stupid, but it is something I have
been working on all day and haven't found a solution yet.

If you go into Notepad and try the keystroke ALT+4, you get a nice little
diamond. Infact, you can do this all the way up to 127 showing different
characters including those similar with the ASCII table for letters and
numbers.

"Oh," I thought, "this could be the simple way for very simple encoding of
our log files." We are looking for an efficient way of encoding log files in
real time. Doing simple subtractions and additions on the character value to
offset them would be confusing for most novices to figure out upon
inspections of the log file (we are not looking for anything ultra secure
here).

But when I run my program and it starts logging the file, I get nice little
boxes instead of the images. Even in debug mode those characters (var =
"☺";) will turn to boxes as well before even going out to the file.

I tried using the System.Text.Enc oding stuff, but I get confused while
working with it.... perhaps this is not the correct thing to use.

Does anyone know how I can preserve those characters and put them to a log
file? Or is there a simpler way to encode my log file in real time? (
Rijndael and
TripleDES algs make our log files way to large).

Thank you all for reading this.
Dec 14 '05 #1
10 1400
If you just want something simple, it is easy to typecast characters to
integers and visa versa. You could use an algorithm like ROT13
(http://www.wikipedia.org/wiki/ROT13). If you want to use an algorithm
like that, character '0' is decimal 48, and 'z' is 122.

Loop through each character and get the integer, then add a value to
it, and convert back to a character.

int dec = (int)currentCha r;
dec += 15;
if (dec > 122) dec -= 75;
newString += (char)dec;

That should confuse the "novices."

Dec 14 '05 #2
Hello KH,

Thank you for replying.

We are looking for a simple way to "encrypt" text to a log file in real time
that has very low overhead for the processor, yet still keeping the log files
the same size.

We decided that a simple distortion of the ASCII values would suffice
according to an offset, like in the code below:

buildString += (char)(charStri ng[i] - (31 - (key2)));

// ex, could be: buildString += (char)(charStri ng[i] - 25);
// so a lower case g (103 on ASCII table) would print as a capital N (78 on
ASCII Table)

This is located in a while loop performing this on every character. I
though that I could shift as low as 31 downwards nd still be safe since
notepad shows symbols for ALT+1 and so on.

This is sort of like a kids decoder ring saying that an A really is a L and
so forth, except key2 is randomized each time so it is harder for the person
reading the log line-by-line to translate and read.

This would cause our log files to be the same size since it is just a 1-to-1
character substitution.

Not very secure, but it will deture the bulk of the people from reading our
logs like they have in the past.

However, I did find this article from The Code Project in light of you
suggested. ...

http://www.codeproject.com/csharp/Base64EncDec.asp

It almost appears this method will cause our logs to grow by about 30%...so
I will have to check on that. I don't know how much overhead this is for the
processor either so I will have to bench mark it.

Thanks,

Rob K

"KH" wrote:
What exactly are you trying to do? I think you're confusing encoding and
encrypting.

Assuming you're writing text to your log file, it is already encoded in one
of many many many text encodings (like us-ascii, Windows-1252, UTF-32,
iso-8859-13, big5, ...)

As a guess you may want to look up Base 64 encoding - it may accomplish what
you want.
"RobKinney1 " wrote:
Hello everyone... This may sound really stupid, but it is something I have
been working on all day and haven't found a solution yet.

If you go into Notepad and try the keystroke ALT+4, you get a nice little
diamond. Infact, you can do this all the way up to 127 showing different
characters including those similar with the ASCII table for letters and
numbers.

"Oh," I thought, "this could be the simple way for very simple encoding of
our log files." We are looking for an efficient way of encoding log files in
real time. Doing simple subtractions and additions on the character value to
offset them would be confusing for most novices to figure out upon
inspections of the log file (we are not looking for anything ultra secure
here).

But when I run my program and it starts logging the file, I get nice little
boxes instead of the images. Even in debug mode those characters (var =
"☺";) will turn to boxes as well before even going out to the file.

I tried using the System.Text.Enc oding stuff, but I get confused while
working with it.... perhaps this is not the correct thing to use.

Does anyone know how I can preserve those characters and put them to a log
file? Or is there a simpler way to encode my log file in real time? (
Rijndael and
TripleDES algs make our log files way to large).

Thank you all for reading this.

Dec 14 '05 #3
RobKinney1 wrote:
Hello everyone... This may sound really stupid, but it is something I have
been working on all day and haven't found a solution yet.

If you go into Notepad and try the keystroke ALT+4, you get a nice little
diamond. Infact, you can do this all the way up to 127 showing different
characters including those similar with the ASCII table for letters and
numbers.

"Oh," I thought, "this could be the simple way for very simple encoding of
our log files." We are looking for an efficient way of encoding log files in
real time. Doing simple subtractions and additions on the character value to
offset them would be confusing for most novices to figure out upon
inspections of the log file (we are not looking for anything ultra secure
here).

But when I run my program and it starts logging the file, I get nice little
boxes instead of the images. Even in debug mode those characters (var =
"☺";) will turn to boxes as well before even going out to the file.

I tried using the System.Text.Enc oding stuff, but I get confused while
working with it.... perhaps this is not the correct thing to use.

Does anyone know how I can preserve those characters and put them to a log
file? Or is there a simpler way to encode my log file in real time? (
Rijndael and
TripleDES algs make our log files way to large).

Thank you all for reading this.


I don't think shifting the ascii value is a good approach. If you are
looking for something fairly simple, I would just Base64 encode. Its
fairly easy to use and will preserve the value of the bytes.

System.Convert. ToBase64String
System.Convert. FromBase64Strin g
--
Rob Schieber
Dec 14 '05 #4
KH
What exactly are you trying to do? I think you're confusing encoding and
encrypting.

Assuming you're writing text to your log file, it is already encoded in one
of many many many text encodings (like us-ascii, Windows-1252, UTF-32,
iso-8859-13, big5, ...)

As a guess you may want to look up Base 64 encoding - it may accomplish what
you want.
"RobKinney1 " wrote:
Hello everyone... This may sound really stupid, but it is something I have
been working on all day and haven't found a solution yet.

If you go into Notepad and try the keystroke ALT+4, you get a nice little
diamond. Infact, you can do this all the way up to 127 showing different
characters including those similar with the ASCII table for letters and
numbers.

"Oh," I thought, "this could be the simple way for very simple encoding of
our log files." We are looking for an efficient way of encoding log files in
real time. Doing simple subtractions and additions on the character value to
offset them would be confusing for most novices to figure out upon
inspections of the log file (we are not looking for anything ultra secure
here).

But when I run my program and it starts logging the file, I get nice little
boxes instead of the images. Even in debug mode those characters (var =
"☺";) will turn to boxes as well before even going out to the file.

I tried using the System.Text.Enc oding stuff, but I get confused while
working with it.... perhaps this is not the correct thing to use.

Does anyone know how I can preserve those characters and put them to a log
file? Or is there a simpler way to encode my log file in real time? (
Rijndael and
TripleDES algs make our log files way to large).

Thank you all for reading this.

Dec 14 '05 #5
RobKinney1 <Ro********@dis cussions.micros oft.com> wrote:
Thank you for replying.

We are looking for a simple way to "encrypt" text to a log file in real time
that has very low overhead for the processor, yet still keeping the log files
the same size.


There are various ways you can do that, but frankly it becomes easier
if you treat the data as binary - encode it (eg using Encoding.UTF8 or
Encoding.Unicod e) and then do whatever simple "encryption " you want.
However, that way you will *not* get logs which are viewable in
notepad. Is that really an issue for you? I would have thought you only
wanted log files which, if sent to you, you can decode.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 14 '05 #6
KH
Correct, base 64 will increase your files by about a third from whatever
encoding you're converting from, since it uses 4 bytes to encode 3 bytes.
Here's a good article on how it works:

http://email.about.com/cs/standards/...4_encoding.htm

Also while I'm sure that code example works, there's already base 64
encoding classes in .NET - see Convert.ToBase6 4String and
Convert.FromBas e64String.

You still need to know what text encoding you're going to and from to use it
properly.

"RobKinney1 " wrote:
Hello KH,

Thank you for replying.

We are looking for a simple way to "encrypt" text to a log file in real time
that has very low overhead for the processor, yet still keeping the log files
the same size.

We decided that a simple distortion of the ASCII values would suffice
according to an offset, like in the code below:

buildString += (char)(charStri ng[i] - (31 - (key2)));

// ex, could be: buildString += (char)(charStri ng[i] - 25);
// so a lower case g (103 on ASCII table) would print as a capital N (78 on
ASCII Table)

This is located in a while loop performing this on every character. I
though that I could shift as low as 31 downwards nd still be safe since
notepad shows symbols for ALT+1 and so on.

This is sort of like a kids decoder ring saying that an A really is a L and
so forth, except key2 is randomized each time so it is harder for the person
reading the log line-by-line to translate and read.

This would cause our log files to be the same size since it is just a 1-to-1
character substitution.

Not very secure, but it will deture the bulk of the people from reading our
logs like they have in the past.

However, I did find this article from The Code Project in light of you
suggested. ...

http://www.codeproject.com/csharp/Base64EncDec.asp

It almost appears this method will cause our logs to grow by about 30%...so
I will have to check on that. I don't know how much overhead this is for the
processor either so I will have to bench mark it.

Thanks,

Rob K

"KH" wrote:
What exactly are you trying to do? I think you're confusing encoding and
encrypting.

Assuming you're writing text to your log file, it is already encoded in one
of many many many text encodings (like us-ascii, Windows-1252, UTF-32,
iso-8859-13, big5, ...)

As a guess you may want to look up Base 64 encoding - it may accomplish what
you want.
"RobKinney1 " wrote:
Hello everyone... This may sound really stupid, but it is something I have
been working on all day and haven't found a solution yet.

If you go into Notepad and try the keystroke ALT+4, you get a nice little
diamond. Infact, you can do this all the way up to 127 showing different
characters including those similar with the ASCII table for letters and
numbers.

"Oh," I thought, "this could be the simple way for very simple encoding of
our log files." We are looking for an efficient way of encoding log files in
real time. Doing simple subtractions and additions on the character value to
offset them would be confusing for most novices to figure out upon
inspections of the log file (we are not looking for anything ultra secure
here).

But when I run my program and it starts logging the file, I get nice little
boxes instead of the images. Even in debug mode those characters (var =
"☺";) will turn to boxes as well before even going out to the file.

I tried using the System.Text.Enc oding stuff, but I get confused while
working with it.... perhaps this is not the correct thing to use.

Does anyone know how I can preserve those characters and put them to a log
file? Or is there a simpler way to encode my log file in real time? (
Rijndael and
TripleDES algs make our log files way to large).

Thank you all for reading this.

Dec 15 '05 #7
Do you think that the 64bit encoding is fairly fast with low overhead... I
may consider that....

Thanks,

Rob K

"Rob Schieber" wrote:


I don't think shifting the ascii value is a good approach. If you are
looking for something fairly simple, I would just Base64 encode. Its
fairly easy to use and will preserve the value of the bytes.

System.Convert. ToBase64String
System.Convert. FromBase64Strin g
--
Rob Schieber

Dec 15 '05 #8
Thank you all for your help. I have since found out through peoples
comments, like Jon Skeet's, that notepad does not correctly display some of
the characters
although their ASCII value is really kept.

I think that in the future I may use the 64 bit encryption as suggested by
Rob Schieber.

I think everything is working at the moment, so thank you all for your
input. :-)

Rob K
Dec 15 '05 #9
Hey, nice web page Jon. I think I may book mark it.

Your comment with notepad made me realize that the characters were actually
preserved, just that notepad itself coudn't display them.

Everything seems to be working.

Thanks again for your help.

Rob K

"Jon Skeet [C# MVP]" wrote:
RobKinney1 <Ro********@dis cussions.micros oft.com> wrote:
Thank you for replying.

We are looking for a simple way to "encrypt" text to a log file in real time
that has very low overhead for the processor, yet still keeping the log files
the same size.


There are various ways you can do that, but frankly it becomes easier
if you treat the data as binary - encode it (eg using Encoding.UTF8 or
Encoding.Unicod e) and then do whatever simple "encryption " you want.
However, that way you will *not* get logs which are viewable in
notepad. Is that really an issue for you? I would have thought you only
wanted log files which, if sent to you, you can decode.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 15 '05 #10

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

Similar topics

48
4601
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 once) * regular expression search & replace. Normally my documents are encoded with the ISO setting. Recently I was writing an XHTML...
4
3159
by: Basil | last post by:
Hello. I have compiler BC Builder 6.0. I have an example: #include <strstrea.h> int main () { wchar_t ff = {' s','d ', 'f', 'g', 't'};
7
9004
by: Michael Davis | last post by:
Hi, I've known C/C++ for years, but only ever used ascii strings. I have a client who wants to know how gcc handles unicode. I've found the functions utf8_mbtowc, utf8_mbstowcs, utf8_wctomb and utf8_wcstombs, but I'm wondering if there are any other libraries or functions which can do things like handle different kinds of encodings? ...
7
5481
by: c duden | last post by:
I am attempting to encrypt some text and be able to decrypt it at a later time. I have two methods to do this: public static Byte EncryptText(string textToEncrypt, string encryptionHash) { Byte bytearrayinput = StringAndByteManipulation.ConvertStringToByteArray(textToEncrypt); //DES instance...
11
6499
by: Beeeeeeeeeeeeves | last post by:
Hi I'm looking for some .net example code on encryption: I don't want anything fancy, no complex third party components with sophisticated algorithms, explanations of principle, or "public/private key" confusion (which seems to be all google can come up with) - I just want a SIMPLE example of how I can encrypt a string and then get back the SAME...
14
6553
by: Xarky | last post by:
Hi, I would like to enrypt and decrypt a simple line of text, with a private(symmetric) key. I have tried searching in the System.Cryptography class, but I can't find a simple way of doing this job. Can someone recommend me an easy way on how to do it. Thanks in Advance
3
3598
by: Shahid | last post by:
Hi, I am trying to display the encrypted value on the console. When I use the following UnicodeEncoding encoding = new UnicodeEncoding( ); string constructedString = encoding.GetString(encryptedData); And I print constructedString on to the console, I see "??????" When I
18
34093
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found Encoding.Convert, but that needs byte arrays. Thanks, /Ger
14
6391
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should I go about doing it ? Thanks
0
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
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 we have to send another system

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.