Problems restraining read command to 32 bits -perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems restraining read command to 32 bits -perl
# 1  
Old 07-15-2009
Problems restraining read command to 32 bits -perl

Hey everybody,

I'm having difficulty using the read command to perform a checksum operation. Whenever I print the final checksum, the result always returns FFFFFFFF, and I know thats not the checksum.

Code:
 #!/usr/bin/perl -w
  
  use strict;
  use FileHandle;
  use warnings;
  my $data = "file.bin";
  my $buffer;
  my $string;
  my $n = 0;
  my $checksum = 0;
  my $num = 0;
  my $str = unpack("B32", pack("N", shift));
  my $bits = 4;
  my $decimal;

open FILE, $data or die $!;
binmode FILE;  
 while (($n = read FILE, $buffer, 4))
 {
 
 $decimal = unpack("N", pack("B32", $buffer));
 
 {$checksum = $checksum + $decimal;
 #$num = $num + $bits;}
 
 #print "1. $num\n";
 print "2. $decimal\n";
 #print "3. $n bytes read\n";
 print "4. $checksum \n";
 }
 
 $checksum = $checksum & 0xFFFFFFFF;

Basically, I'm trying to read a binary file 32 bits at a time by unpacking them into decimal and then adding them. Furthermore, I am trying to use the $checksum & 0xFFFFFFFFF command to restrain the checksum to 32 bits. Also, just ignore the commented out stuff, I was using it for my own testing. Any assistance would be greatly appreciated.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

2. What is on Your Mind?

Place Bits & Win Bits!!! - 17th Annual Satellite Awards

Ten movies have been nominated as best motion picture by the International Press Academy, presentation of the 2012 Satellite Awards will be held on 16th December at Los Angeles, CA. Place your bits here on one of the below nominated movie of your choice:- Argo ... (0 Replies)
Discussion started by: Yoda
0 Replies

3. Shell Programming and Scripting

how to read tail -F command output in perl

Hi All, How I will read the output of the tail -F command in perl. I have text file with below contains file1.txt 1 2 3 4 $running=1; sub openLog($) { (my $log) = @_; (1 Reply)
Discussion started by: pravin27
1 Replies

4. UNIX for Dummies Questions & Answers

32 bits procesaor with 64 bits Solaris

people i have a problem i have a 32 bits sparc processor, and solaris 64 bits processor, i install a oracle data base 64 bits, but my oracle will not run because my processor is from 32 bits this is ok??, i know if i have x86 i cannot install a 64 bits operatin system in a 32 bits processor. ... (0 Replies)
Discussion started by: enkei17
0 Replies

5. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

6. AIX

How to convert a partition usin 64 bits kernel to 32 bits kernel?

Hello there: I know that exist a procedure to convert an OS using 32bits kernel to 64 bits kernel. But, exist a procedure to convert an OS using 64bits to 32 bits kernel? Please help me. Regards. (2 Replies)
Discussion started by: GEIER
2 Replies

7. Shell Programming and Scripting

Problems while read a file

Hello guys, i need your help, let me try to explain what i need: I have a file (plain text) for example with 500 lines, i need to read only from the line 200 until the end of file, and serch the word 'ERROR' onli between lines 200 and 500, that have sence? Thanx for your help. (7 Replies)
Discussion started by: lestat_ecuador
7 Replies

8. UNIX for Dummies Questions & Answers

Changing 24 bits to 8 bits display

Hello all, I was wondering if anyone can tell me how to change 24 bits depth display to 8 bits depth display for Sun Ultra1, running Solaris 8? THANKS in advance. I think that the command is ffbconfig, but it has nothing about depth. (4 Replies)
Discussion started by: larry
4 Replies
Login or Register to Ask a Question
FIPSCHECK(8)							     fipscheck							      FIPSCHECK(8)

NAME
fipscheck - perform a FIPS-140-2 validation check of one or more files SYNTAX
fipscheck [-s <hmac-suffix>] file1 [file2 ...] DESCRIPTION
fipscheck will perform a FIPS-140-2 validation of a file using a stored checksum of a file. The file containing the checksum value is first looked up in the /usr/lib{64,}/fipscheck directory and if not found there, it will be searched for in the same directory as the file which is being checksummed. The checksum file must have '.' prepended and '.hmac' appended to the original file name. The '.' must not be prepended to the file names in the /usr/lib{64,}/fipscheck directory. If invoked correctly the fipscheck command will not print anything to the standard output or error and set the return code based on the test result. A return code of 0 means the file passed the checksum test. A value of non-zero means the checksum failed. The -s option allows to specify the suffix of the hmac file names. The default value .hmac is used when this option is not specified. RETURN CODES
fipscheck can return the following return codes: 0 Checksum OK 1 Checksum mismatch 2 Missing filename 3 Cannot open the checksum file 4 Cannot read the file to be checksummed, or the checksum computation failed 5 Memory allocation error 10 and higher - Failure during self-checking the libfipscheck.so shared library 20 and higher - Failure during self-checking the fipscheck binary ENVIRONMENT VARIABLES
If you set the environment variable FIPSCHECK_DEBUG to "error", all error messages are sent to stderr. Setting this variable to "syslog" will send all error messages to the syslog daemon. FIPS MODE
A kernel compiled with CONFIG_CRYPTO_FIPS=y can be booted in fips mode by specifying fips=1 as kernel parameter. If the /boot director resides on a different partition, this needs to be specfied, for example boot=/dev/sda2. SEE ALSO
fipshmac(8), fipscheck.h(3), https://fedorahosted.org/fipscheck/ AUTHOR
Tomas Mraz <tmraz@redhat.com>. Man page by Paul Wouters <pwouters@redhat.com> COPYRIGHT
Copyright 2008, 2012 Red Hat, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. fipscheck April 11, 2012 FIPSCHECK(8)