简体   繁体   English

Reed Solomon或PHP中的其他FEC编码器和解码器

[英]Reed Solomon or other FEC Encoder and Decoder in PHP

I have inherited a PHP project that could really, really benefit from a form of Forward Error Correction, as it involves (potentially) the users typing in a base64 encoded string of an infinitely variable length. 我继承了一个PHP项目,该项目可能确实会从前向纠错的形式中真正受益,因为它涉及(潜在地)用户键入无限长的base64编码字符串。 This string is split into groups of 6 characters at present for human ease of transcription and joined back together before processing, but by virtue of introducing humans into the equation errors can and do still occur. 为了便于人类转录,目前将该字符串分为6个字符的组,并在处理之前将其重新连接在一起,但是由于将人类引入等式中,错误仍然会发生,并且确实会发生。

Short strings, or those copy-and-pasted are generally fine. 短字符串或复制粘贴的字符串通常都可以。 The outliers of manually-typed lengthy ones are where the real benefit would be seen. 手动键入冗长的异常值是可以看到真正好处的地方。

I've settled on Reed Solomon being the most likely candidate for achieving this (but I'm happy to be pointed towards a more appropriate FEC by those with more practical experience). 我认为里德·所罗门(Reed Solomon)是实现这一目标的最有可能的候选人(但我很高兴被有更多实践经验的人指点为更合适的FEC)。

Does anyone know of an open source RS encoder and decoder I can use within this PHP application? 有谁知道我可以在此PHP应用程序中使用的开源RS编码器和解码器? I have found several ENcoders I can probably hack at from QRCode libraries but a decoder seem to be mythical. 我已经从QRCode库中找到了几个可以从中破解的ENcoder,但是解码器似乎是神话。 I do of course have the option of taking several C implementations and re-writing them (I'm a programmer not a math expert, so writing one from scratch is probably beyond me). 我当然可以选择采用几种C实现并重新编写它们(我不是程序员,而是数学专家,因此从头开始编写它可能超出了我的范围)。

The data at present looks like this (representation only, probably not valid base64!): 当前数据如下所示(仅表示形式,可能无效的base64!):

fD48Sa 483CDf 18ACDx UYh5jS PQXNT

I'd either like to apply RS encoding to each block after it has been split (lengthening each block, I accept that and it would be acceptable from a project point of view), OR apply it before the string is split into blocks of 6. From what I understand of RS however that would be the more complex option as the string is then not a fixed length. 我想在分割后将RS编码应用于每个块(加长每个块,我接受,并且从项目的角度来看是可以接受的),或者在将字符串分成6个块之前应用根据我对RS的了解,这将是更复杂的选择,因为字符串不是固定长度。

What I was hoping to be able to find after the 'eureka' moment of coming up with the FEC idea was something that would allow me to do this: 在提出FEC想法的“尤里卡”时刻之后,我希望能够找到的东西可以让我做到这一点:

// messy encode pseudocode for demonstration purposes
$data    = "Once upon a time in a land far far away";
$encoded = base64_encode($data);
$split   = chunk_split($encoded, 6, ' ');

foreach($split as $chunk) {
    $rsEncoded .= rsEncode($chunk) . " ";
}

and then then a similar rsDecode() when it is input. 然后输入类似的rsDecode()。

Any hints appreciated... 任何提示表示赞赏...

I may be misunderstanding your problem, but it doesn't sound like a good use case for forward error correction. 我可能会误解您的问题,但这听起来不像是前向纠错的好用例。

Forward error correction is useful when the message is known to be correct at the point when the encoding takes place. 当已知消息在编码发生时是正确的时,前向纠错很有用。 Errors introduced after this point can be overcome during the decoding process. 此后引入的错误可以在解码过程中克服。 However, from the workflow you're describing, it sounds as though you want to encode the message after the user has entered it, which is too late to detect any errors in their transcription. 但是,从您描述的工作流程中,听起来好像您想在用户输入消息后对消息进行编码,这为时已晚,无法检测到其抄录中的任何错误。

It's possible that you're actually describing receiving a Reed Solomon code block, having the user enter their data, and using the check symbols from the received code block to analyze their data. 您可能实际上是在描述接收一个Reed Solomon代码块,让用户输入他们的数据,并使用接收到的代码块中的校验符号来分析他们的数据。 If the number of symbols that differ between the entered data and the received code block is less than the Singleton bound of your RS code, this will indeed allow you to 'correct' the user's input to the message that you received in the first place. 如果输入的数据和接收到的代码块之间的符号数小于RS代码的Singleton界限,则确实可以使您“校正”用户输入的信息,使其成为您最初收到的消息。 I'm not sure why this would be useful, though. 我不确定为什么这会有用。


That said, I believe the easiest way to get RS up and running in PHP would be to call a Python implementation from the PHP code. 就是说,我相信在PHP中启动和运行RS的最简单方法是从PHP代码中调用Python实现

Wikiversity has a very well documented Python encoder/decoder here , and a further generalized version of the same implementation here . 维基有一个非常有据可查的Python编码器/解码器在这里 ,同样实施的进一步的通用版本在这里 I found both of those resources to be immensely useful when writing my own C++ implementations recently. 我发现最近编写我自己的C ++实现时,这两种资源都非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM