|
Could you please post the few lines of code you changed?
When I decode:
FTTFTADTFATTDDDTDTDTTDDDDDDTADDFFTAADDTFATDFTTAADTAFDDFAAFFTADDFA
the USPS results are: 00700123456123456792605211234
but this decoder gives: 15814079586565956792604312759
which is obviously incorrect.
Thanks - Gylfi
|
|
|
|
|
One of the most important problems that I found was in the following code. Additions are remarked with my initials. 'bgh
I discovered that examples like the one you provided (FTTFTADTFATTDDDTDTDTTDDDDDDTADDFFTAADDTFATDFTTAADTAFDDFAAFFTADDFA) that would result in a -1 index value in the table 5of13 and in the table2of13, my code does a 3rd test of index <0 and sets test = not test and 8191 then rechecks the table2of13
For i = 0 To 9
Dim test = ad(i), index = Array.IndexOf(table5of13, test)
If (index < 0) Then
test = Not test And 8191
index = Array.IndexOf(table5of13, test)
If (index < 0) Then
test = ad(i) 'bgh
index = Array.IndexOf(table2of13, test)
If (index < 0) Then ' bgh
test = Not test And 8191 'bgh
index = Array.IndexOf(table2of13, test) 'bgh
End If 'bgh
index += 1287
End If
End If
ad(i) = index
Next
In the next section I made these changes.
'original code start
For i = 2 To 19
OneCodeMathAdd(byteArray, 13, -r)
OneCodeMathDivide(byteArray, 10)
r = OneCodeMathMod(byteArray, 10)
result = r.ToString() & result
Next
OneCodeMathAdd(byteArray, 13, -r)
OneCodeMathDivide(byteArray, 5)
r = OneCodeMathMod(byteArray, 5)
result = r.ToString() & result
OneCodeMathAdd(byteArray, 13, -r)
OneCodeMathDivide(byteArray, 10)
'original code end
' my code start
For i = 2 To 18 'bgh only loop 2 to 18 because the 19th test should be mod 5
OneCodeMathAdd(byteArray, 13, -r)
OneCodeMathDivide(byteArray, 10)
r = OneCodeMathMod(byteArray, 10)
result = r.ToString() & result
Next
OneCodeMathAdd(byteArray, 13, -r)'bgh
OneCodeMathDivide(byteArray, 10) 'bgh
r = OneCodeMathMod(byteArray, 5) 'bgh 19 divide by 10 is then mod 5
result = r.ToString() & result 'bgh
OneCodeMathAdd(byteArray, 13, -r) 'bgh
OneCodeMathDivide(byteArray, 5) ' bgh now divide by 5 and mod 10
r = OneCodeMathMod(byteArray, 10) 'bgh
result = r.ToString() & result ' bgh last result
OneCodeMathAdd(byteArray, 13, -r)' bgh
OneCodeMathDivide(byteArray, 10) 'one last divide by 10
'my code end
Those are the changes that I made to get the correct results that match the postal decoder.
my version of the decoder result =
00700123456123456792605211234
|
|
|
|
|
Was not sure how to post the code, so I hope it appears correctly in the previous message, found that html was botching some of my response so I reposted with corrections.
|
|
|
|
|
I wanted to make another comment about the first for next loop.
If at any time (index = -1) prior to the (index +=1287) it is a very good indication that the barcode being decoded is invalid.
If a value of -1 reaches that line of code the code will continue with a decode result, but the result really should be invalid.
If the index is still -1 with the code changes I made, then the test was not found in the table.
To test this, type in a random series of ATFD letters, and use the decode routine. There will be a result, but it would likely fail on the Postal decoder.
The correct place to test for an invalid code would be a result of -1 at this section...
If (index < 0) Then ' bgh
test = Not test And 8191 'bgh
index = Array.IndexOf(table2of13, test) 'bgh
End If 'bgh
insert
if index = -1 then
message box invalid code etc....
endif
index += 1287
|
|
|
|
|
Thanks a lot for posting these fixes - this is very helpful.
I inted to take the mailText.txt file that the USPS provides and run that through both the USPS decoder and this one and compare the results. If all of those barcodes yield the same results, then we're probably in good shape. I'll let you know.
Thanks again - Gylfi
|
|
|
|
|
Please let me know the results and where do I get this mailText.txt?
Gylfi Ingvason wrote:
I inted to take the mailText.txt file that the USPS provides and run that through both the USPS decoder and this one and compare the results.
|
|
|
|
|
The mailText.txt is available at the USPS IMB download site at:
https://ribbs.usps.gov/index.cfm?page=intellmailmailpieces
The file contains 1257 addresses and associated IMB barcodes that are broken down into into components for testing. After applying your fixes posted earlier, the decoding of all these barcodes match the results of the USPS decode web site. Nice job!
You have to sign up for a user-id/password to access the USPS site, and it took them a few weeks to issue mine if I remember correctly. It seems absurd that they don't just make this stuff public, but it's the government we're talking about, so who knows what the thinking is.
If you are interested, send me a private e-mail to
gylfi@computer.org
and I'll e-mail you the file. I don't think I'll be breaking any laws in doing so, but like I said, all of them match now. Thanks a bunch for taking the time to debug this - it surely is appreciated.
Best regards,
Gylfi
|
|
|
|
|
These changes are not reflected in either your VB or your C# code -- can you please make the changes & repost your source code? Also, please run the 4 samples from the USPS IMb Specification SPUSPSG - I'm experiencing progressive error as the DP ZIP content increases:
"01234567094987654321"
"0123456709498765432101234"
"01234567094987654321012345678"
"0123456709498765432101234567891"
This fixes the error:
For i = 0 To 9
Dim test = ad(i), index = Array.IndexOf(table5of13, test)
If (index < 0) Then
test = Not test And 8191
index = Array.IndexOf(table5of13, test)
If (index < 0) Then
test = ad(i) 'bgh
index = Array.IndexOf(table2of13, test)
If (index < 0) Then ' bgh
test = Not test And 8191 'bgh
index = Array.IndexOf(table2of13, test) 'bgh
End If 'bgh
index += 1287
End If
End If
ad(i) = index
Next
ad(9) = CType(ad(9) \ 2, Integer)
If (ad(0) > 658) Then ad(0) -= 659
OneCodeMathMultiply(byteArray, 13, 659) 'added missing multiply
OneCodeMathAdd(byteArray, 13, ad(0))
For i = 1 To 8
OneCodeMathMultiply(byteArray, 13, 1365)
OneCodeMathAdd(byteArray, 13, ad(i))
Next
OneCodeMathMultiply(byteArray, 13, 636)
OneCodeMathAdd(byteArray, 13, ad(9))
r = OneCodeMathMod(byteArray, 10)
result = r.ToString() & result
For i = 2 To 18 'bgh only loop 2 to 18 because the 19th test should be mod 5
OneCodeMathAdd(byteArray, 13, -r)
OneCodeMathDivide(byteArray, 10)
r = OneCodeMathMod(byteArray, 10)
result = r.ToString() & result
Next
OneCodeMathAdd(byteArray, 13, -r)'bgh
OneCodeMathDivide(byteArray, 10) 'bgh
r = OneCodeMathMod(byteArray, 5) 'bgh 19 divide by 10 is then mod 5
result = r.ToString() & result 'bgh
OneCodeMathAdd(byteArray, 13, -r) 'bgh
OneCodeMathDivide(byteArray, 5) ' bgh now divide by 5 and mod 10
r = OneCodeMathMod(byteArray, 10) 'bgh
result = r.ToString() & result ' bgh last result
OneCodeMathAdd(byteArray, 13, -r)' bgh
OneCodeMathDivide(byteArray, 10) 'one last divide by 10
' at this point all that remains is the encoded DP ZIP - convert to int and skip to the "if rest > 1000100001" section
I also have a JavaScript/JScript version validated against all USPS test cases.
modified on Thursday, November 4, 2010 1:12 AM
|
|
|
|
|
Are you saying that you still experience errors after you apply my fixes or that you would like drdigit to apply the fixes?
|
|
|
|
|
Yes -- there are still errors in the code. I've fixed the errors and rehosted to JScript and validated the revised code against the 20K USPS test cases (download the last two download files located at https://ribbs.usps.gov/onecodesolution/download.cfm) but be aware of four problems with the test cases: only the first error found is returned, not a complete diagnostic, and decoder error returns "01" and "02" are both set to return only a "01", error return "03" is being improperly reported as "02" and error return "12" is misreported as "09" in the test cases, inconsistent from the specification. Perhaps the USPS shouldn't have used a Canadian contractor .....
modified on Thursday, April 14, 2011 10:56 AM
|
|
|
|
|
You have saved me days of work!
I'm curious as to your motivation for this project?...
|
|
|
|
|
I used your class to verify my C# implementation (didn't find yours in time to just use it). Anyway, when I ran 11,000 unique addresses through both of our encoding routines I found three that failed to match from your implementation to mine. Using the USPS encoder (http://ribbs.usps.gov/OneCodeSolution/Barcode_Encoder.Aspx) I found one of them was due to a bug in the BigInteger class I used within my implementation. I did not take time to find why your VB implementation did not match the USPS results for the other two missmatches. FYI-Here are the two test cases that may have an issue:
1) Tracking#: 00 700 888888 010159052
PostNet: 57325052828
USPS: TDTDF FADFT AFFDF ADTAD DDATF AATFT DDDAD FDTFT FDFFT FFFAD AFFDA DADDA FDDDD
vb: TDDTT DAFDD FAADA TDATF DTDTA ATFFD ADFAF TDDAT FFTDT DTAAD FFDTF TATTT FDFFA
2) Tracking#: 00 700 905016001 174945
PostNet: 57325052828
USPS: TAFTT TDFAF DTTTA DAFFF FADDF FATDF TADFA DDFTF AAFTF FTTTF FTFAA ADTTD FAADA
vb: ATTDT FTTAF TAFTT DTDDA FATTT FAFAD AAFTF TTATT TADFF ADDAF TFDAA FFFTD AFDFA
Thank You-Very Much!
brian
|
|
|
|
|
Thank you for sharing the results of your test cases. They helped me solve the problem (the update is already emailed for upload).
During the debugging process I used the USPS online tools. According to USPS, encoded information is unique, meaning that decoding generates unique information for any given group of bars. By using the errors you tracked I found that the official decoder (http://ribbs.usps.gov/OneCodeSolution/Barcode_Decoder.Aspx) generates exactly the same initial information for different groups of bars. The pairs I used are as follows:
Bars 1: TDDTTDAFDDFAADATDATFDTDTAATFFDADFAFTDDATFFTDTDTAADFFDTFTATTTFDFFA
Bars 2: TDTDFFADFTAFFDFADTADDDATFAATFTDDDADFDTFTFDFFTFFFADAFFDADADDAFDDDD
Common Result: 00 700 888888 010159052 57325052828
|
|
|
|
|
How Hard would this be to convert to PHP?
It would be sweet to be able to use this with web applications!
***edit***
I have been doing my best to translate to PHP, but I do need a little more help in order to release this script and help others...
Please help me anyone!
Please help Dr Digit. I am sure you know how hard that specification pack is to follow
I will be forever grateful to whoever helps me help others with this port!
Just let me know an email to send the code to! (about 300 lines)
|
|
|
|
|
This code works grat thanks, it was exactly what I was looking for.
USPS does ship their thing with compiled dlls and a cryptic c++ code.
thanks!
hp
|
|
|
|
|
|
You have done a great job getting through the USPS jibberish to come up with this code. My question is do you have code for a Decoder? The USPS states that they can't supply any code (a decoder is on their web site) just sudo code.
|
|
|
|
|
Hopefully I'll find the time needed to write the decoder code within this weekend. Please check for an update next week.
|
|
|
|
|
Where is the pseudo code?
|
|
|
|
|
Finally I found the time to write the routine and submit it for update.
It's ???, but after all these months there is no other decoder implementation with source code on the net!!!
|
|
|
|
|
See optional code fix in the "Incorrect decode example" thread. Resolves incorrect decodes.
|
|
|
|
|
This is great but I think there may be something wrong with the VB.NET decoder. I have verified the encoding but the decoding is incorrect.
The following is what I get...
Original 5337977723499454492851135759461
Encoded DAFDTDAFFDFTDADTDDFTTFDTATATFFFDFTTFFFTFDDTDAAFATDFTFDFDTTTDTTFDA
Decoded 4837977723499454492851135759461
|
|
|
|
|