Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone,

i am working on encryption & decryption of data. i have done with encryption & decryption & then i am converting that string into hex number. now i have issue of final string having very long in length.

i want to make it as small string up to 16 character long.
actual string is given below,

77003400470031007300570055006B0039004E006300430042004100690054005400300030004B0048006F004C0055006D005400740055003500410036005100

can any one have a reference or links that help me in converting above string into small length string.

I have tried Hex to Decimal, but still problem is there.

Is there any alternative way of doing it?
Any kind of link, suggestion and specially expert advice would be highly appreciated.

Regards,
Balkrishna Raut
Posted
Comments
CPallini 12-Jan-11 5:42am    
Your requirement isn't clear. Reducing string size wouldn't wipe out your original data?

If your string always has the obvious pattern of "xx00", you could do this when storing the string:

C#
string value = "77003400470031007300570055006B0039004E";
value = value.Replace("00", "");


and that would cut the string length by almost 50%. But at that point, you would have to put the "00" back before using it again. That would require a bit more code. I'd probably write an extension method that returned an array of two character strings, and then iterate through the returned array to rebuild a single string, adding the "00" where appropriate.

I honestly don't know of a way to reduce the length of the string other than after eliminating the "00", you convert the objects hex values to ascii text equivalents which would reduce the size of the string again by 50%, but you're still not going to get it to 16 characters in length...

 
Share this answer
 
v3
I assume that you want to split the string into 16 character segments, so how about:
String.Substring[^]

string s="77003400470031007300570055006B00"+
         "39004E00630043004200410069005400"+
         "5400300030004B0048006F004C005500"+
         "6D005400740055003500410036005100";

string s1 = s.Substring(0,16);
string s2 = s.Substring(16,16);

.... 
  // and so on, probably better to 
  // rewrite this and put it into a loop


Regards
Espen Harlinn
 
Share this answer
 
v3
 
Share this answer
 
You can do string compression/decompression

Here is the example
http://madhu-dotnetblog.blogspot.com/2008/10/how-to-compress-decompress-strings-in-c.html
 
Share this answer
 
v2

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