summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-11-13 07:47:22 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2014-02-11 02:07:50 (GMT)
commit9af8df8066ab20357de58e7b2a3a3c9fe517e69b (patch)
tree36f8c9c1ef520001050e33518cdea905c3255826
parentd968971f04a1c843350e37009da36abd29c0b042 (diff)
downloadabc8000-9af8df8066ab20357de58e7b2a3a3c9fe517e69b.zip
abc8000-9af8df8066ab20357de58e7b2a3a3c9fe517e69b.tar.gz
abc8000-9af8df8066ab20357de58e7b2a3a3c9fe517e69b.tar.bz2
abc8000-9af8df8066ab20357de58e7b2a3a3c9fe517e69b.tar.xz
data: crc16 and csum32 scripts
Add scripts to show crc16 and csum32 of larger data objects
-rwxr-xr-xdata/crc16.pl20
-rwxr-xr-xdata/csum32.pl14
2 files changed, 34 insertions, 0 deletions
diff --git a/data/crc16.pl b/data/crc16.pl
new file mode 100755
index 0000000..2515fb9
--- /dev/null
+++ b/data/crc16.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use bytes;
+
+$c = 0;
+
+while (read(STDIN, $data, 4096) > 0) {
+ foreach $b (unpack("C*", $data)) {
+
+ for ($i = 7; $i >= 0; $i--) {
+ $x = ($b >> $i) & 1;
+
+ $x ^= ($c & 0x8000) >> 15;
+ $c = ($c & 0x7fff) << 1;
+ $c ^= ($x ? 0x1021 : 0x0000);
+ }
+ }
+}
+
+printf "%04x\n", $c;
diff --git a/data/csum32.pl b/data/csum32.pl
new file mode 100755
index 0000000..dcf4cb2
--- /dev/null
+++ b/data/csum32.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use bytes;
+
+$c = 0;
+
+while (read(STDIN, $data, 4096) > 0) {
+ foreach $b (unpack("N*", $data)) {
+
+ $c = ($c + $b) & 0xffffffff;
+ }
+}
+
+printf "%08x\n", $c;