📄 maxicode.c
字号:
} if (den == 0) {#if DEBUG >= 1 printf("\n ERROR: denominator = 0\n");#endif /* Convert to dual- basis */ count = -1; goto finish; } /* Apply error to data */ // if (num1 != 0) { // data[loc[j]] ^= Alpha_to[modnn(Index_of[num1] + Index_of[num2] + GPRIME - Index_of[den])]; // } if (debug) { printf("Num1=%d I_of[num1]=%d num2=%d I_of[num2]=%d den=%d I_of[den]=%d \n", num1, Index_of[num1], num2, Index_of[num2], den, Index_of[den] ); } error_val = Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])]; if (debug) { printf("Error val = %d Index_of[error_val] = %d modnn = %d\n", error_val, Index_of[error_val], modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])); printf("Data[fixloc] = %d \n", data[data_len-loc[j]]); } /* Apply error to data */ if (num1 != 0) { if ( loc[j] < data_len + 1 ) { fix_loc = data_len - loc[j]; if (debug) { printf("Fix loc = %d \n", fix_loc); } if ( fix_loc < data_len + 1) { data[fix_loc] = (data[fix_loc] ^ error_val); } } } } finish: if(eras_pos != NULL){ for(i=0;i<count;i++){ if(eras_pos!= NULL) eras_pos[i] = loc[i]; } } return count;}int poly_mult( int mult1, int mult2){ int log1; int log2; int result; int logres; int debug; debug = 0; if ((mult1 > 63) || ( mult1 < 0)) { printf("Internal error in poly_mult call\n"); exit(0); } if (( mult2 > 63 ) || (mult2 < 0)) { printf("Internal error in poly_mult call\n"); exit(0); } if (( mult1 == 0 ) || (mult2 == 0)) { if (debug) { printf("Returning 0 \n"); } return(0); } log1 = bin_expgood[ mult1]; log2 = bin_expgood[ mult2]; if (debug) { printf(" in poly mult - mult1 = %d mult2 = %d \n", mult1, mult2); printf(" in poly mult log1 = %d log2 = %d \n", log1, log2); } if (debug) { printf("Log1 = %d log2 = %d log1 + log2 = %d \n",log1,log2, log1+log2 ); } logres = ( log1 + log2 ) % 63; if (debug) { printf("logres = %d \n", logres ); } result = exp_bingood[logres]; return(result);} void put_back_len(int inval ) { int debug; debug = 0; if (debug) { printf("Put back len, Code = %d \n",inval); } codes[0] = inval ; data[0]= inval; } /* put back len */// calculate syndromes for the encoded message + correction// this is to check to see that the error correction codes are correct//// in general, there are half as many syndromes as error correction codewordsvoid syndromes(UInt32 *data, int message_len, int synd_count ){ int i, j; int power_val; int synd_val; int s_index; int npower; int debug; debug = 0; if ( RS_init == FALSE) { generate_gf(); } for ( i =0; i < synd_count; i += 1) { synd_array[i] =0; } for ( i =0; i < synd_count; i += 1) { // power_val = powers_of_2[i+1]; power_val = Alpha_to[i+1]; if (debug) { printf("Power val = %d \n", power_val); } synd_val = 0; for(j=0; j < message_len; j += 1) { synd_val = (data[j] ^ synd_val) & 0x3f; synd_val = poly_mult(power_val, synd_val); // s_index = Index_of[synd_val]; // synd_val = Alpha_to[modnn((i+1) * s_index)]; if (debug) { printf("Sval = %d \n", synd_val); } if (debug) { printf("data[%d] = %d \n", j,data[j]); } } synd_array[i] = synd_val; if (debug) { printf("i = %d syndrome = %d \n",i, synd_array[i]); } }} void nc(char *instring) { int ll; int jj; int slen; char tempstr[256]; char short_str[256]; int val[10]; int nondigit; int long_val; slen = strlen(instring); printf("In nc - strlen = %d \n",slen); printf("In string = %s \n",instring); if (strlen(instring) < 9) { nondigit = FALSE; for (jj = 0; jj < strlen(instring); jj += 1) { if (isdigit(instring[jj])) { } else { nondigit= TRUE; } } if (nondigit == FALSE) { long_val = atol(instring); val[0] = (long_val & 0x3f000000) >> 24; val[1] = (long_val & 0xfc0000) >> 18; val[2] = (long_val & 0x3f000 ) >> 12; val[3] = (long_val & 0xfc0 ) >> 6; val[4] = (long_val & 0x3f); for ( jj = 0; jj < 6; jj += 1) { put_back(val[jj]); } } } } /* nc */ /* byte compact a string */void outbit(FILE *fp, int bit){ static int col = 0; fprintf(fp, bit ? "1" : "0"); /* if (++col == 68) { fprintf(fp, "\n"); col = 0; } */} void test_nc() { char this_string[120]; printf(" String = '12' Result = 112 \n"); this_string[0] = '1'; this_string[1] = '2'; this_string[2] = NULLCHAR; nc(this_string); printf(" String = '199' Result = 1, 299 \n"); this_string[0] = '1'; this_string[1] = '9'; this_string[2] = '9'; this_string[3] = NULLCHAR; nc(this_string); printf(" String = '81030499' Result = 223, 444, 899 \n"); this_string[0] = '8'; this_string[1] = '1'; this_string[2] = '0'; this_string[3] = '3'; this_string[4] = '0'; this_string[5] = '4'; this_string[6] = '9'; this_string[7] = '9'; this_string[8] = NULLCHAR; nc(this_string); printf("End test nc \n"); }int get_cvalue_codeset(unsigned char inchar, int * Code_set_ret) { int code_set; int value; int value2; if (inchar == NULLCHAR) { return(0); } if (inchar < 127) { if (isalpha((unsigned char)inchar) || isdigit((unsigned char)inchar)) { /* A-Z a-z or 0-9 */ if (isalpha( inchar)) { /* A-Z or a-z */ if (isupper( inchar)) { /* A-Z */ value = inchar - 'A' + 1; code_set = 1; } else { value = inchar - 'a' + 1; code_set = 2; } } else { value = inchar - '0' + 48; code_set = 1;; } } else { // 58 = . in codeset 1,2 switch(inchar) { case 31: value = 31; code_set=1; break; case '&': value = 38; code_set=1; break; case ',': value = 44; code_set=3; value2 = 48; break; case ':': value = 58; code_set=3; value2 = 51; break; case '#': value = 35; code_set=1; break; case CR : value = 0; code_set=1; break; case HT : value = 9; code_set=16; break; case '-': value = 46; code_set=2; break; case '.': value = 46; code_set=3; value2 = 49; break; case '$': value = 36; code_set=1; break; case '/': value = 47; code_set=3; value2 = 50; break; case '+': value = 43; code_set=1; break; case '%': value = 37; code_set=1; break; case '*': value = 42; code_set=1; break; case '=': value = 39; code_set=2; break; case '^': value = 45; code_set=2; break; case ' ': value = 32; code_set=3; value2 = 47; break; case ';': value = 37; code_set=2; break; case '<': value = 38; code_set=2; break; case '>': value = 40; code_set=2; break; case '@': value = 52; code_set=2; break; case '[': value = 42; code_set=2; break; case '\\': value = 43; code_set=2; break; case ']': value = 44; code_set=2; break; case '_': value = 46; code_set=2; break; case '~': value = 35; code_set=2; break; case '!': value = 53; code_set=2; break; case LF: value = 10; code_set=16; break; case '"': value = 34; code_set=1; break; case '|': value = 54; code_set=2; break; case '(': value = 40; code_set=1; break; case ')': value = 41; code_set=1; break; case '?': value = 41; code_set=2; break; case '{': value = 32; code_set=2; break; case '}': value = 34; code_set=2; break; case '\'': value = 43; code_set=2; break; default: value = 26; code_set=6; printf("Internal error: unknown charactor = %c (%d) \n",inchar , inchar); } } } else // handle international code_set = 3, 4, 5 { } *Code_set_ret = code_set; return(value);} #define TRUE 1 #define FALSE 0/* expand \CR \LF \BS \NL */ void expand_string( char *instring) {char tempstr[256];char newstr[256];int parseok;int debug;int ii, jj; char numstr[32]; int numval; int num_count; debug = 0; strcpy(tempstr,instring); ii = 0; jj = 0; while (ii < strlen(tempstr)) { if ( tempstr[ii] == BACKSLASH ) { parseok = FALSE; if (( tempstr[ii+1] == 'L') && ( tempstr[ii+2] == 'F')) { newstr[jj] = LF; ii += 3; jj += 1; parseok = TRUE; } if (( tempstr[ii+1] == 'C') && ( tempstr[ii+2] == 'R')) { newstr[jj] = CR; ii += 3; jj += 1; parseok = TRUE; } if (( tempstr[ii+1] == 'B') && ( tempstr[ii+2] == 'S')) { newstr[jj] = BACKSLASH; ii += 3; jj += 1; parseok = TRUE; } if (( tempstr[ii+1] == 'N') && ( tempstr[ii+2] == 'L')) { newstr[jj] = CR; newstr[jj+1] = LF; ii += 3; jj += 2; parseok = TRUE; } // numeric shift!!! if (( tempstr[ii+1] == 'N') && ( tempstr[ii+2] == 'S')) { num_count = 0; numstr[0] = NULLCHAR; while( (isdigit(tempstr[ii+3+ num_count])) && ( num_count < 9)) { numstr[num_count] = tempstr[ii+3+num_count]; num_count += 1; numstr[num_count+1] = NULLCHAR; } newstr[jj] = 31; numval = atoi(numstr); newstr[jj+1] = (0x3f000000 & numval) >> 24; newstr[jj+2] = (0xfc0000 & numval) >> 18; newstr[jj+3] = (0x3f000 & numval) >> 12; newstr[jj+4] = (0xfc0 & numval) >> 6; newstr[jj+5] = (0x3f & numval); ii += 3 + num_count; jj += 6; parseok = TRUE; } if (( tempstr[ii+1] == 'G') && ( tempstr[ii+2] == 'S')) { newstr[jj] = GS; ii += 3; jj += 1; parseok = TRUE; } if (( tempstr[ii+1] == 'F') && ( tempstr[ii+2] == 'S')) { newstr[jj] = FS; ii += 3; jj += 1; parseok = TRUE; } if (( tempstr[ii+1] == 'R') && ( tempstr[ii+2] == 'S')) { newstr[jj] = RS; ii += 3; jj += 1; parseok = TRUE; } if (parseok == FALSE) { newstr[jj] = tempstr[ii]; jj += 1; ii += 1; printf("Warning text string has single backslash \n"); printf(" Use \\BS if you want a back slash \n"); } } else { newstr[jj] = tempstr[ii]; ii += 1; jj += 1; } } newstr[jj] = NULLCHAR; if (debug) { for (ii = 0; ii < strlen(newstr); ii += 1) { printf(" newstr [%d] = %d - %c \n", ii, newstr[ii], newstr[ii] ); } } strcpy(instring, newstr ); } // expand string void do_text_string(char *instring) { int this_prev_type; int prev_value; int prev_type; int end_of_text; int symbol_char; char new_char; char new_charp1; char new_charp2; char new_charp3; char new_charp4; int value1; int value2; int value3; int value4; int type1; int type2; int type3; int type4; int ccount; int dcount; int ecount; int jj; int num_type_found; int debug; int total_chars; int index; int typetemp; int symbol_char_array[2000]; int single_punctuation; int single_capital; int ii; debug = 0; prev_value = 0; prev_type = 8; end_of_text = FALSE; ccount = 0; ecount = 0; dcount = 0; total_chars = 0; jj = 0; if (debug) { printf("In do_text_string - instring = %s \n",instring); } if (debug) { for ( ii = 0; ii < strlen(instring); ii += 1) { printf("Char %d = %d \n", ii, instring[ii] ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -