#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    2
    Rep 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. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    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? :)

IMN logo majestic logo threadwatch logo seochat tools logo