Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 1st, 2002, 09:30 AM
 converge
Junior Member

Join Date: Aug 2002
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
how to encode a 7 character long string into a 5 character long string

I have a series of strings that are 7 characters long each. My problem is this: these strings contain important product information that needs to be encoded. However these strings need to be encoded into 5 character long strings and encoded in such a way that just by reading the string values don't give away valuable information. The process needs to be reversable (convert the encoded 5 character long strings into 7 characters long). Thanks.

#2
August 1st, 2002, 10:55 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,534
Time spent in forums: 2 Months 3 Days 5 h 3 m 14 sec
Reputation Power: 4106
This might actually be a question to be asked in the algorithm forum, but I'll try to answer it here. It's possible to do this, provided you give some information about what the possible range of characters is in the 7 character string.

Assuming that the characters used are only A-Z (uppercase or lowercase alone) and maybe a few other characters like space, comma, period etc. here's how I'd do it.

We have to compress our data into a 5 byte array. Therefore we have 5 Bytes = 40 bits (because each byte = 8 bits)

Assume a 5 bit baudot character set. This means that 5 bits will be used to represent each character, so there can be a maximum of 2^5 = 32 characters in this set. A-Z will take up 26 of these characters, leaving 6 free characters which you can use for characters such as space, period, comma and three other characters of your choosing. Now, if each character uses up 5 bits, then to represent 7 characters in this set, you'll need (7 x 5) = 35 bits

Therefore, you can squeeze 7 characters into a 5 byte array using this 5 bit character set. Matter of fact, you can squeeze an 8th character in there as well, or use the remaining 5 bits for status, parity or checksum bits of some sort. Does this give you an idea how to proceed?

 Viewing: Dev Shed Forums > Programming Languages > C Programming > how to encode a 7 character long string into a 5 character long string