Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

When I tried to get number of bytes of a character in chinese it displayed 1 to 4 bytes corresponds to each character.Also found that the Dec values of each one is greater than 127.So I need each one in 7 bit length and remaining will shift to next byte level inorder to get the Dec value less than 127.

For example 227,131,162 is the byte level representation of the character 'モ'.So what I need is to get 7 bit from first byte level and shift remaining one bit to next byte level(that is to 131).From this I will get each Dec representation less than 127.

Please help me
Thanks in advance.
Posted
Updated 8-Aug-11 20:48pm
v2
Comments
OriginalGriff 9-Aug-11 3:14am    
Why? what are you trying to achieve that you think you need this?
kutz 2 9-Aug-11 3:24am    
Yes I need this.
OriginalGriff 9-Aug-11 3:40am    
No, why do you need it? Characters are the way they are for a reason - what are you trying to do that you think you need to rip them apart and bit shift them?

227,131,162 is the same as E3 83 A2 in hexadecimal. If you shift this value 1 bit right you will get 71 C1 D1 which is 113,193,209. So you still don't have what you want and also these values represent a totally different character. Perhaps your explanation needs to be made clearer.
 
Share this answer
 
Comments
kutz 2 9-Aug-11 4:31am    
Ok I will explain.I need to encrypt these character.So first I want to get a Dec value less than 127 corresponds to each byte and then will do some operation on it.
[EDIT]
I used some C# encryption algorithms for encryption.This results too length output.I think in this case I will get maximum 4 length size for each character
Richard MacCutchan 9-Aug-11 5:52am    
You are either totally misunderstanding this data, or not explaining your problem clearly. You cannot remove any bits from these characters to make the values less than 128, encrypt and decrypt them, and expect to recreate the originals. If you wish to encrypt data then just use the built in encryption features, taking your characters as an array of 8-bit bytes.
Encryption does not need 7 bit characters - it works on byte data (which is 8 bit). Your Chinese characters will be taken as byte data and encoded (and decoded) correctly without the need for you to play with the data bits.


"I am trying to encrypt each character so that an array of character results a chunk of data as like number of drops results a water.Now we are deviating the actual purpose.Could you please give any idea about what I am asked"

I don't think it is going to help you much, as the "characters" is generates are still not printable, but...
Try:
C#
byte[] data = new byte[3];
Random r = new Random();
r.NextBytes(data);
char[] chars = new char[4];
chars[0] = (char) (data[0] & 0x7f);
chars[1] = (char) (((data[0] & 0x80) >> 7) | ((data[1] & 0x3F) << 1));
chars[2] = (char) (((data[1] & 0xC0) >> 6) | ((data[2] & 0x1F) << 2));
chars[3] = (char) (((data[2] & 0xE0) >> 5));


If your input data is:
b0    abcd efgh
b1    ijkl mnop
b2    qrst uvwx

then this treats it as a least significant bit stream and generates:
c0     bcd efgh
c1     klm nopa
c2     tuv wxij
c3          qrs
You will still probably be better off going with a "proper" encryption algorithm, though...
 
Share this answer
 
v2
Comments
kutz 2 9-Aug-11 5:09am    
Is there any rule that the encryption should use 7 bit.I think we can encrypt and decrypt a character in any way so that the main purpose is security.Also I know I don't want to play with data bits for the encoding and decoding of chinese character.I just trying to encrypt the chinese character
OriginalGriff 9-Aug-11 5:17am    
No, there is no rule that encryption should use 7 bit data - is works on eight bit at all times, even if the "spare" bit is zero.
Don't encrypt single characters: encrypt as large a chunk of data as you can. That way it is a lot harder to decrypt without the key.

Why are you trying to encrypt individual characters? You do realize that any bit shuffling technique is about as secure as a tissue-paper safe...:laugh:
kutz 2 9-Aug-11 5:23am    
I am trying to encrypt each character so that an array of character results a chunk of data as like number of drops results a water.Now we are deviating the actual purpose.Could you please give any idea about what I am asked
OriginalGriff 9-Aug-11 6:10am    
Answer updated
kutz 2 9-Aug-11 5:26am    
Also please note that I am not just shuffling but after that will do some operation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900