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>2010-11-13 07:47:22 (GMT)
commitc300ae6318c7f083ca429264c26f3ea312ae5110 (patch)
tree15569b4d7bc0d610d4287858e27075d18e913bf4
parented38d4e51a493fe901a24acc437634283eb97b04 (diff)
downloadabc8000-old-c300ae6318c7f083ca429264c26f3ea312ae5110.zip
abc8000-old-c300ae6318c7f083ca429264c26f3ea312ae5110.tar.gz
abc8000-old-c300ae6318c7f083ca429264c26f3ea312ae5110.tar.bz2
abc8000-old-c300ae6318c7f083ca429264c26f3ea312ae5110.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;