|

The Charmsec code is an error-correcting code invented by the author and is a block code that encodes data into printable characters.
The name 'Charmsec' is derived from Characterized Reminder Set Error Correcting code.
This code can tolerate errors in characters in the code characters and can decode them. The following example implementation can deal with a single character error.
There are a number of ranges (super data) that can be handled beyond the size of the data length by using the surplus of information entropy.
In the implementation example below, LF (0x0a) can be used as a code delimiter with 1-bit error correction.
It is suitable for device-to-device communications in asynchronous serial communications such as RS-232, RS-422, and RS-485.
Suitable for applications where both real-time performance and transmission efficiency are required (e.g., transmission of control signals for industrial robots and vehicles).
Printable characters facilitate logging and e-mail attachments.
As the required resource is as small as 8 kbytes, it can be easily implemented in a relatively small systems.
There are several types of Charmsec codes, the followings are some of the most popular ones in practical use.
Example of Charmsec code character mapping to 7-bit ASCII code (Delimiter : LF, Excluded character : ∖)
Note 1 : NL (0x0A) can be used as a code block delimiter with 1-bit error correction since 1-bit errors in NL (0x0A) are mapped not to be a code character.
Note 2 : Since ∖ (0x5C) is also excluded from the code character, ∖ can be used as an error position indicator, etc.
Charmsec7_5C Single-character error correcting characterization code
Encodes 44-bit data into a 9-char ASCII string. Excluded characters are ∖.
The encoding rate is about 0.698. Compared to Base64, the encoded character is increased by approximately 22%.
Examples of Encoding and Decoding
Sun, 25 Aug 2024 05:16:42 +0900 Charmsec7_5c_demo : Rev.1.97 (Aug. 25, 2024) (c) 2004 Takayuki HOSODA, Finetune co., ltd. Charmsec7_5c_demo : Using charmsec8_5c - a subset of the Charmsec CoDec library. Charmsec7_5c_demo : '\' is to be used as the error position indicator here. Charmsec7_5c_demo : txdata = 0x0000badcafebabe -> txcode = gMbVtv'no Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = \MbVtv'no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = g\bVtv'no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gM\Vtv'no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gMb\tv'no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gMbV\v'no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gMbVt\'no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gMbVtv\no - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gMbVtv'\o - Corrected an error Charmsec7_5c_demo : rxdata = 0x0000badcafebabe <- rxcode = gMbVtv'n\ - Corrected an error Charmsec7_5c_demo : txdata = 0x000141d4a551717 -> txcode = ikquwyzdm (saturated) Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = \kquwyzdm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = i\quwyzdm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ik\uwyzdm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ikq\wyzdm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ikqu\yzdm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ikquw\zdm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ikquwy\dm (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ikquwyz\m (superdata) - Corrected an error Charmsec7_5c_demo : rxdata = 0x000141d4a551717 <- rxcode = ikquwyzd\ (superdata) - Corrected an error
▼ Charmsec7_5C Implementation Example (Click to expand)Download archive : charmsec7_5c_demo-1.97.tar.gz [4kB tar.gz]
Example of Super Data Usage
One of the features of Charmsec is the use of super data to send one-shot data or control codes in between data streams, It can also be used for end of data stream, check bits, timestamps, etc.
The figure below shows an example of using Charmsec7 in RS-485 multi-drop communication between a device and a robot.
![]()
Technical Explanation (In Japanese)
▼ Excerpt from the patent specification (click to expand)Afterword
Majority-vote error correction based on the Chinese Remainder Theorem (CRT) is founded on the following idea. Given a set of n + 2t mutually orthogonal unit vectors, if an original number can be represented in 1 + 2t different ways as a set of n values obtained from inner products with these vectors, then up to t errors can be corrected by applying a majority decision to the corresponding decoding results.
This structure of decomposing a number and mapping its components is also hoped to provide some insight for future research on orthogonal modulation schemes and quantum error correction.
Technical Documents
Patent Gazette Patent No. 7142977 — Data Communication System, Transmitting Device, and Receiving DeviceChange history
▼ Change history (click to expand)SEE ALSO
© 2021, Takayuki HOSODA, Finetune co., ltd.
- (5-char, 16-bit) error-correcting characterization code containing no confusing characters
- An Example of Numerical Calculation Using Modular Arithmetic
- Absolute Encoder (Patent No. 6083034)
- BCHTX — Binary-to-text conversion program with 2-bit error correction and error detection
- Binary BCH Codes and Burst Error Correction Codes
- Motor Driver (Patent No. 5979649)
![]()
![]()
![]()
![]()