#!/usr/bin/perl $_ = ; $arch = $_; print $arch . "\n"; $header = substr($arch, 0, 257); # header len is 257 total print $header. "\n"; $header =~ s/ZZ/../g; $before_cs = substr($header, 0, 148); # before the chksum is first 147 bytes $after_cs = substr($header, 148+7, 100); # chksum is bytes 148 through 156 (8 bytes) $meat = substr($arch, 148+8+100); $sp_replace = " "x7; $blanked_header = $before_cs . $sp_replace . $after_cs; print $blanked_header . "\n"; my $chk; for $offset (0..length($header)) { $chr = substr($header, $offset, 1); $chk = ord($chr) + $chk; } $chk = "0" + $chk; print "checksum :$chk\n"; open ($tarfh, ">", "x.tar"); print $tarfh $before_cs . "0" . $chk . $after_cs . $meat; close ($tarfh);