Skip to content

Commit d390ecf

Browse files
authored
Merge pull request #1 from 3-O/master
Add X-25 CRC
2 parents 703a531 + 6fd2432 commit d390ecf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

crc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type Parameters struct {
2222
}
2323

2424
var (
25+
// X-25 CRC parameters, also known as CRC-16/IBM-SDLC, CRC-16/ISO-HDLC, CRC-B
26+
X25 = &Parameters{Width: 16, Polynomial: 0x1021, Init: 0xFFFF, ReflectIn: true, ReflectOut: true, FinalXor: 0xFFFF}
2527
// CCITT CRC parameters
2628
CCITT = &Parameters{Width: 16, Polynomial: 0x1021, Init: 0xFFFF, ReflectIn: false, ReflectOut: false, FinalXor: 0x0}
2729
// CRC16 CRC parameters, also known as ARC

crc_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func TestCRCAlgorithms(t *testing.T) {
3939
}
4040
}
4141

42+
doTest(X25, "123456789", 0x906E)
43+
doTest(X25, "12345678901234567890", 0xA286)
44+
doTest(X25, "Introduction on CRC calculations", 0xF9B6)
45+
doTest(X25, "Whenever digital data is stored or interfaced, data corruption might occur. Since the beginning of computer science, people have been thinking of ways to deal with this type of problem. For serial data they came up with the solution to attach a parity bit to each sent byte. This simple detection mechanism works if an odd number of bits in a byte changes, but an even number of false bits in one byte will not be detected by the parity check. To overcome this problem people have searched for mathematical sound mechanisms to detect multiple false bits.", 0x68B1)
46+
4247
doTest(CCITT, "123456789", 0x29B1)
4348
doTest(CCITT, "12345678901234567890", 0xDA31)
4449
doTest(CCITT, "Introduction on CRC calculations", 0xC87E)

0 commit comments

Comments
 (0)