我使用 Python 库 pdf417gen 创建了一个 pdf417 条形码。
条形码是字符串“M1LONG”的图形表示。条码有两个数据列,Reed Solomon 纠错安全级别设置为“1”。这表明在输入八个数据码字的情况下,纠错码字的数量应该是四个。
Python 输出将 D07 到 D00 的数据代码字显示为{8, 389, 902, 11, 900, 344, 396, 900}
. python 将 C03 到 C00 的纠错码字列为{718, 801, 313, 877}
. 这是用于生成所有代码字的 Python:
from builtins import range
from .data import ERROR_CORRECTION_FACTORS
def compute_error_correction_code_words(data_words, level):
assert 0 <= level <= 8
# Correction factors for the given level
factors = ERROR_CORRECTION_FACTORS[level]
# Number of EC words
count = 2 ** (level + 1)
# Correction code words list, prepopulated with zeros
ec_words = [0] * count
# Do the math
for data_word in data_words:
temp = (data_word + ec_words[-1]) % 929
for x in range(count - 1, -1, -1):
word = ec_words[x - 1] if x > 0 else 0
ec_words[x] = (word + 929 - (temp * factors[x]) % 929) % 929
return [929 - x if x > 0 else x for x in reversed(ec_words)]
纠错码字是使用多项式、伽罗瓦域算术和模数 929 的补码生成的,这是 pdf417 系统可能的码字数。计算使用许多因素来简化过程。对于安全级别 1,建议的因子数为 4。因素是522,568,723,809
http://grandzebu.net/informatique/codbar/pdf417coef.txt
问题是这样的。我尝试使用从http://grandzebu.net/informatique/codbar-en/pdf417.htm获得的 JAVA 伪代码重新创建错误代码字
我编写了一个 JAVA 程序来尝试生成与上述 Python 软件相同的代码字,但它不会生成相同的错误代码字。
JAVA程序编译并运行,数学在我未经训练的眼中看起来不错,但产生的错误代码不一样。这是我的 JAVA,JAVA 变量被称为与 Python 相同,以便于比较两个程序。
import java.util.Arrays;
public class reedsolomon{
public static void main (String[] args){
int ec_words[] = new int[4];//correction codewords array
int temp=0;//holding variable
int count=4; //number of error correction codewords
int data_words[] = {8,389,902,11,900,344,396,900};// eight data codewords array D7 to D0.
int factors[]= {522,568,723,809}; //factors or coefficients array.
for(int i=0; i<data_words.length-1; i++) {
temp=(data_words[i] + ec_words[count-1])%929;
for(int x=count-1; x>-1; x--){
if(x==0){
ec_words[x] = (929-(temp*factors[x])%929)%929; //negative values in the Galois Field
//GF(929) are equal to the complement of itself if
//ec_words[x] > -929
}
else{
ec_words[x]=(ec_words[x-1]+929-(temp*factors[x])%929) %929; //negative values in the Galois Field
//GF(929) are equal to the complement of the
//remainder (ec_words[x] /929) if ec_words[x] <= -929.
}
}
}
for(int j=0; j<count; j++){
if(ec_words[j] != 0){
ec_words[j]=929-ec_words[j];
}
}System.out.println("Error codewords are " + Arrays.toString(ec_words));
}
}
我将不胜感激知道 JAVA 代码的问题是什么,它阻止它生成与库 pdf417gen 中包含的 python 程序相同的错误代码字。