/*
Golay 23.12 code encoding and decoding (using lookup table)
Generator polynomial: x11+x10+x6+x5+x4+x2+1
Golay 23.12 is perfect code with Hamming distance of 7,
and can correct up to 3 errors per codeword.
More than 3 errors are NOT detected.
The parity extended Golay 24.12 code has D=8 and can
correct up to 3 and detect 4 errors.
(c)VLV
vlv@writeme.com
http://www.geocities.com/SiliconValley/4795
*/
#include <stdio.h>
/*
Generate Golay 23.12 codeword
(Generator polynomial: x11+x10+x6+x5+x4+x2+1)
input = 12-bit data
output = 23-bit codeword
*/
unsigned long int MakeGolayWord(unsigned int x)
{
unsigned char ci;
unsigned int s;
s=x;
for(ci=0;ci<12;ci++)
{
s<<=1;
if(s&0x1000) s^=0x08ea;
}
s=(s>>1)&0x7ff;
return (((unsigned long int)x)<<11)|s;
}
/*
Correct Golay 23.12 codeword using syndrome lookup table
(Generator polynomial: x11+x10+x6+x5+x4+x2+1)
Can correct up to 3 errors,don't detect more than 3 errors (perfect code)
input - pointer to codeword;
returns the number of errors corrected (0,1,2,3)
*/
unsigned char CorrectGolayCode(unsigned long int *golayword)
{
// The lookup table consists of 15-bit values
static unsigned int const correction_table[2048] =
{
0x7fff,0x7fe0,0x7fe1,0x7c01,0x7fe2,0x7c02,0x7c22,0x0022,
0x7fe3,0x7c03,0x7c23,0x0023,0x7c43,0x0043,0x0443,0x15d1,
0x7fe4,0x7c04,0x7c24,0x0024,0x7c44,0x0044,0x0444,0x3616,
0x7c64,0x0064,0x0464,0x2e74,0x0864,0x2135,0x19f2,0x1d4c,
0x7fe5,0x7c05,0x7c25,0x0025,0x7c45,0x0045,0x0445,0x0dd1,
0x7c65,0x0065,0x0465,0x09d1,0x0865,0x05d1,0x01d1,0x7dd1,
0x7c85,0x0085,0x0485,0x1d0f,0x0885,0x194b,0x3295,0x2653,
0x0c85,0x31b2,0x2556,0x1a15,0x1e13,0x3e96,0x216d,0x11d1,
0x7fe6,0x7c06,0x7c26,0x0026,0x7c46,0x0046,0x0446,0x1e75,
0x7c66,0x0066,0x0466,0x214d,0x0866,0x3214,0x11f2,0x2576,
0x7c86,0x0086,0x0486,0x2591,0x0886,0x154b,0x0df2,0x21d4,
0x0c86,0x1dd6,0x09f2,0x1615,0x05f2,0x3633,0x7df2,0x01f2,
0x7ca6,0x00a6,0x04a6,0x4a96,0x08a6,0x114b,0x2130,0x31af,
0x0ca6,0x25f3,0x1d6c,0x1215,0x36b6,0x1d12,0x2a74,0x19d1,
0x10a6,0x094b,0x35d3,0x0e15,0x014b,0x7d4b,0x1e36,0x054b,
0x2234,0x0615,0x0215,0x7e15,0x258e,0x0d4b,0x15f2,0x0a15,
0x7fe7,0x7c07,0x7c27,0x0027,0x7c47,0x0047,0x0447,0x1a75,
0x7c67,0x0067,0x0467,0x2612,0x0867,0x2daf,0x2296,0x114c,
0x7c87,0x0087,0x0487,0x150f,0x0887,0x4654,0x256e,0x0d4c,
0x0c87,0x19d6,0x3635,0x094c,0x1613,0x054c,0x014c,0x7d4c,
0x7ca7,0x00a7,0x04a7,0x110f,0x08a7,0x2596,0x29b2,0x2e14,
0x0ca7,0x2a95,0x196c,0x3676,0x1213,0x1912,0x25f5,0x1dd1,
0x10a7,0x050f,0x010f,0x7d0f,0x0e13,0x35d5,0x1a36,0x090f,
0x0a13,0x2571,0x3a54,0x0d0f,0x7e13,0x0213,0x0613,0x154c,
0x7cc7,0x00c7,0x04c7,0x0a75,0x08c7,0x0675,0x0275,0x7e75,
0x0cc7,0x11d6,0x156c,0x3e34,0x2551,0x1512,0x35d0,0x0e75,
0x10c7,0x0dd6,0x2a14,0x2db2,0x218d,0x25f0,0x1636,0x1275,
0x01d6,0x7dd6,0x2133,0x05d6,0x2e95,0x09d6,0x1df2,0x194c,
0x14c7,0x3611,0x0d6c,0x254e,0x39f4,0x0d12,0x1236,0x1675,
0x056c,0x0912,0x7d6c,0x016c,0x0112,0x7d12,0x096c,0x0512,
0x2655,0x3274,0x0a36,0x190f,0x0636,0x1d4b,0x7e36,0x0236,
0x29af,0x15d6,0x116c,0x1e15,0x1a13,0x1112,0x0e36,0x25b4,
0x7fe8,0x7c08,0x7c28,0x0028,0x7c48,0x0048,0x0448,0x2d92,
0x7c68,0x0068,0x0468,0x194d,0x0868,0x1135,0x1e96,0x3e13,
0x7c88,0x0088,0x0488,0x14ef,0x0888,0x0d35,0x2a33,0x19d4,
0x0c88,0x0935,0x31d0,0x4656,0x0135,0x7d35,0x156d,0x0535,
0x7ca8,0x00a8,0x04a8,0x10ef,0x08a8,0x3674,0x1930,0x2ab6,
0x0ca8,0x2e16,0x4a75,0x2594,0x298f,0x18f2,0x116d,0x21d1,
0x10a8,0x04ef,0x00ef,0x7cef,0x3a56,0x3211,0x0d6d,0x08ef,
0x1a34,0x29d3,0x096d,0x0cef,0x056d,0x1535,0x7d6d,0x016d,
0x7cc8,0x00c8,0x04c8,0x0d4d,0x08c8,0x3e36,0x1530,0x11d4,
0x0cc8,0x054d,0x014d,0x7d4d,0x2dd3,0x14f2,0x3235,0x094d,
0x10c8,0x4253,0x2eb6,0x09d4,0x1d8d,0x05d4,0x01d4,0x7dd4,
0x1634,0x2d8f,0x1d33,0x114d,0x2a16,0x1935,0x21f2,0x0dd4,
0x14c8,0x31d5,0x0930,0x2e33,0x0530,0x0cf2,0x7d30,0x0130,
0x1234,0x08f2,0x39f6,0x154d,0x00f2,0x7cf2,0x0d30,0x04f2,
0x0e34,0x25b6,0x2992,0x18ef,0x3e75,0x214b,0x1130,0x15d4,
0x7e34,0x0234,0x0634,0x2215,0x0a34,0x10f2,0x196d,0x3276,
0x7ce8,0x00e8,0x04e8,0x10af,0x08e8,0x29d0,0x0e96,0x25b1,
0x0ce8,0x3233,0x0a96,0x2dd5,0x0696,0x14d2,0x7e96,0x0296,
0x10e8,0x04af,0x00af,0x7caf,0x198d,0x2e76,0x4255,0x08af,
0x2972,0x3614,0x1933,0x0caf,0x39f1,0x1d35,0x1296,0x214c,
0x14e8,0x048f,0x008f,0x7c8f,0x2e35,0x0cd2,0x31d3,0x088f,
0x25ae,0x08d2,0x2a11,0x0c8f,0x00d2,0x7cd2,0x1696,0x04d2,
0x002f,0x7c2f,0x7c0f,0x7fef,0x2554,0x044f,0x004f,0x7c4f,
0x32b6,0x046f,0x006f,0x7c6f,0x2213,0x10d2,0x1d6d,0x086f,
0x18e8,0x2574,0x3a32,0x3216,0x118d,0x0cb2,0x296f,0x2275,
0x3e15,0x08b2,0x1133,0x1d4d,0x00b2,0x7cb2,0x1a96,0x04b2,
0x098d,0x2a35,0x0d33,0x14cf,0x7d8d,0x018d,0x058d,0x1dd4,
0x0533,0x21d6,0x7d33,0x0133,0x0d8d,0x10b2,0x0933,0x2e11,
0x2a76,0x0872,0x3695,0x10cf,0x0072,0x7c72,0x1d30,0x0472,
0x0052,0x7c52,0x216c,0x0452,0x7c12,0x7ff2,0x0032,0x7c32,
0x2dd0,0x04cf,0x00cf,0x7ccf,0x158d,0x0c92,0x2236,0x08cf,
0x1e34,0x0892,0x1533,0x0ccf,0x0092,0x7c92,0x29d5,0x0492,
0x7fe9,0x7c09,0x7c29,0x0029,0x7c49,0x0049,0x0449,0x29f4,
0x7c69,0x0069,0x0469,0x1e12,0x0869,0x1115,0x31b3,0x1976,
0x7c89,0x0089,0x0489,0x1991,0x0889,0x0d15,0x1d6e,0x1653,
0x0c89,0x0915,0x1556,0x35cf,0x0115,0x7d15,0x4234,0x0515,
0x7ca9,0x00a9,0x04a9,0x2db5,0x08a9,0x1d96,0x1910,0x1253,
0x0ca9,0x19f3,0x1156,0x2194,0x2e54,0x29b0,0x1df5,0x25d1,
0x10a9,0x3a14,0x0d56,0x0a53,0x35f1,0x0653,0x0253,0x7e53,
0x0556,0x1d71,0x7d56,0x0156,0x198e,0x1515,0x0956,0x0e53,
0x7cc9,0x00c9,0x04c9,0x1191,0x08c9,0x35d2,0x1510,0x0d76,
0x0cc9,0x15f3,0x3a95,0x0976,0x1d51,0x0576,0x0176,0x7d76,
0x10c9,0x0591,0x0191,0x7d91,0x4e96,0x1df0,0x29b5,0x0991,
0x2db0,0x2a54,0x1d13,0x0d91,0x158e,0x1915,0x25f2,0x1176,
0x14c9,0x0df3,0x0910,0x1d4e,0x0510,0x4695,0x7d10,0x0110,
0x01f3,0x7df3,0x3632,0x05f3,0x118e,0x09f3,0x0d10,0x1576,
0x1e55,0x21b6,0x2df4,0x1591,0x0d8e,0x254b,0x1110,0x1a53,
0x098e,0x11f3,0x1956,0x2615,0x7d8e,0x018e,0x058e,0x1db4,
0x7ce9,0x00e9,0x04e9,0x0e12,0x08e9,0x1596,0x116e,0x21b1,
0x0ce9,0x0612,0x0212,0x7e12,0x1951,0x3a74,0x15f5,0x0a12,
0x10e9,0x29b3,0x096e,0x52b6,0x056e,0x19f0,0x7d6e,0x016e,
0x31f4,0x1571,0x1913,0x1212,0x3656,0x1d15,0x0d6e,0x254c,
0x14e9,0x0996,0x4674,0x194e,0x0196,0x7d96,0x0df5,0x0596,
0x21ae,0x1171,0x09f5,0x1612,0x05f5,0x0d96,0x7df5,0x01f5,
0x1a55,0x0d71,0x31b0,0x212f,0x2154,0x1196,0x156e,0x1e53,
0x0171,0x7d71,0x1d56,0x0571,0x2613,0x0971,0x11f5,0x19b4,
0x18e9,0x2174,0x35f6,0x154e,0x0d51,0x11f0,0x3254,0x2675,
0x0951,0x31b5,0x1113,0x1a12,0x7d51,0x0151,0x0551,0x1d76,
0x1655,0x09f0,0x0d13,0x1d91,0x01f0,0x7df0,0x196e,0x05f0,
0x0513,0x25d6,0x7d13,0x0113,0x1151,0x0df0,0x0913,0x15b4,
0x1255,0x054e,0x014e,0x7d4e,0x2db3,0x1996,0x1d10,0x094e,
0x4296,0x1df3,0x256c,0x0d4e,0x1551,0x2132,0x19f5,0x11b4,
0x7e55,0x0255,0x0655,0x114e,0x0a55,0x15f0,0x2636,0x0db4,
0x0e55,0x1971,0x1513,0x09b4,0x1d8e,0x05b4,0x01b4,0x7db4,
0x7d09,0x0109,0x0509,0x3a76,0x0909,0x0c95,0x14d0,0x1db1,
0x0d09,0x0895,0x2df1,0x1594,0x0095,0x7c95,0x29d2,0x0495,
0x1109,0x0875,0x3654,0x2970,0x0075,0x7c75,0x31f6,0x0475,
0x0055,0x7c55,0x18f3,0x0455,0x7c15,0x7ff5,0x0035,0x7c35,
0x1509,0x2a32,0x08d0,0x0d94,0x04d0,0x2dcf,0x7cd0,0x00d0,
0x1dae,0x0594,0x0194,0x7d94,0x4676,0x10b5,0x0cd0,0x0994,
0x2d93,0x19b6,0x3a35,0x1d2f,0x1d54,0x0cb5,0x10d0,0x2253,
0x3e12,0x08b5,0x2156,0x1194,0x00b5,0x7cb5,0x256d,0x04b5,
0x1909,0x1d74,0x08b0,0x3e55,0x04b0,0x2993,0x7cb0,0x00b0,
0x3256,0x3a11,0x10f3,0x254d,0x35f4,0x10d5,0x0cb0,0x2176,
0x29cf,0x15b6,0x0cf3,0x2191,0x2e32,0x0cd5,0x10b0,0x25d4,
0x04f3,0x08d5,0x7cf3,0x00f3,0x00d5,0x7cd5,0x08f3,0x04d5,
0x0450,0x11b6,0x7c50,0x0050,0x7c30,0x0030,0x7ff0,0x7c10,
0x2975,0x21f3,0x0870,0x1994,0x0470,0x1d32,0x7c70,0x0070,
0x01b6,0x7db6,0x0890,0x05b6,0x0490,0x09b6,0x7c90,0x0090,
0x2634,0x0db6,0x14f3,0x2dd2,0x218e,0x14d5,0x0c90,0x29f1,
0x1d09,0x1974,0x2995,0x09b1,0x3e53,0x05b1,0x01b1,0x7db1,
0x15ae,0x29f6,0x10d3,0x2212,0x2d90,0x10f5,0x2696,0x0db1,
0x4236,0x31d2,0x0cd3,0x152f,0x1554,0x0cf5,0x216e,0x11b1,
0x04d3,0x08f5,0x7cd3,0x00d3,0x00f5,0x7cf5,0x08d3,0x04f5,
0x0dae,0x4275,0x2e56
- 1
- 2
- 3
前往页