Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

hash function question

D

drrob1

Guest
I'm sure this has already been done, so I'm going to ask b4 I try to do it myself.

I would like to use a select command to feed into one of the hash functions, and have the batch file check the computed hash against a hashcode in a file to see if they match or not.

Thanks
 
drrob1 wrote:
| I would like to use a select command to feed into one of the hash
| functions, and have the batch file check the computed hash against a
| hashcode in a file to see if they match or not.

The only situation when hash code comparison is faster than the @compare
function is when one file needs to be compared with many other files of the
same size. @compare tests every byte of the files only if the two files are
the same size, and there is no difference before the last byte. Hash code
calculations are much slower tha simple comparison, and they may report
false matches (but mismatch reports are always correct), and they must
process the whole file.

That said, I am not sure how SELECT can feed a function. However, it could
feed the batch file, which in turn can pass its parameter to the hash
function (or @compare).
--
HTH, Steve
 
I think you misunderstood my question. I download .iso files frequently
and would like to check their hashes against published info to make sure
that a GB file is correct. I am NOT looking to compare 2 files.

On Sat, 2010-02-06 at 11:05 -0500, Steve F?bi?n wrote:

> drrob1 wrote:
> | I would like to use a select command to feed into one of the hash
> | functions, and have the batch file check the computed hash against a
> | hashcode in a file to see if they match or not.
>
> The only situation when hash code comparison is faster than the @compare
> function is when one file needs to be compared with many other files of the
> same size. @compare tests every byte of the files only if the two files are
> the same size, and there is no difference before the last byte. Hash code
> calculations are much slower tha simple comparison, and they may report
> false matches (but mismatch reports are always correct), and they must
> process the whole file.
>
> That said, I am not sure how SELECT can feed a function. However, it could
> feed the batch file, which in turn can pass its parameter to the hash
> function (or @compare).
 
On Sat, 06 Feb 2010 11:45:11 -0500, drrob106 <> wrote:

|I think you misunderstood my question. I download .iso files frequently
|and would like to check their hashes against published info to make sure
|that a GB file is correct. I am NOT looking to compare 2 files.

It isn't pretty, but this might do what you want.

select echo (*.iso) > filespec.txt & echo crc32 %@crc32[%@line[filespec.txt,0]] & del /q filespec.txt
--
- Vince
 
drrob wrote (1):
| I would like to use a select command to feed into one of the hash
| functions, and have the batch file check the computed hash against a
| hashcode in a file to see if they match or not.

drrob wrote (2):
| I think you misunderstood my question. I download .iso files frequently
| and would like to check their hashes against published info to make sure
| that a GB file is correct. I am NOT looking to compare 2 files.


I responded to the first message assuming "match" in the last
sentence refers to your intent to check whether or not the two files
whose hash codes you compare match, where your program calculates the
hash codes of both files. Your 2nd post clarified that you have no
access to the original file, only to its downloaded hash code, and to
what is hopefully its exact downloaded copy. Vince's response
suggests one method to achieve your goal.

Note that the @compare function can compare your local copy with the
one on an FTP server, albeit quite slowly. In supercritical cases it
might be worth the time.
--
Steve
 
That's what I needed. Thanks

vefatica wrote:

> On Sat, 06 Feb 2010 11:45:11 -0500, drrob106 <> wrote:
>
> |I think you misunderstood my question. I download .iso files frequently
> |and would like to check their hashes against published info to make sure
> |that a GB file is correct. I am NOT looking to compare 2 files.
>
> It isn't pretty, but this might do what you want.
>
> select echo (*.iso) > filespec.txt & echo crc32 %@crc32[%@line[filespec.txt,0]] & del /q filespec.txt
 
This batch file is not working

batmd5:
select /o:-d echo (*) >filespec
set md5hash=%@md5[%@line[filespec,0]]
IFF %md5hash EQ %@line[filespec,1] THEN
echo Matched
ELSE
echo Not Matched
ENDIFF

When the md5hash is set, it is not set to the correct value. The
correct value is displayed when I created the alias as described below
by Vince.

And I am getting an EOF condition when I try %@line[filespec,1]

I suspect that the batch file is computing a hash of the string of the
filename and not its contents. The contents are used for the
computation by the alias.

There are too many dereferencing operators for me.

Thanks

drrob1 wrote:

> That's what I needed. Thanks
>
> vefatica wrote:
> ---Quote---
>> select echo (*.iso) > filespec.txt & echo crc32 %@crc32[%@line[filespec.txt,0]] & del /q filespec.txt
> ---End Quote---
 
Try this

setlocal
unset /q *
bdebugger /ne
select /o:-d echo (*) >filespec

set md5hash=%@md5[f,%@line[filespec,0]]

IFF %md5hash EQ %@md5[f,%@line[filespec,0]] THEN
echo Matched
ELSE
echo Not Matched
ENDIFF
endlocal




----- Original Message -----
Sent: Sunday, February 07, 2010 12:28 PM
Subject: RE: [Support-t-1716] hash function question



> This batch file is not working
>
> batmd5:
> select /o:-d echo (*) >filespec
> set md5hash=%@md5[%@line[filespec,0]]
> IFF %md5hash EQ %@line[filespec,1] THEN
> echo Matched
> ELSE
> echo Not Matched
> ENDIFF
>
> When the md5hash is set, it is not set to the correct value. The
> correct value is displayed when I created the alias as described below
> by Vince.
>
> And I am getting an EOF condition when I try %@line[filespec,1]
>
> I suspect that the batch file is computing a hash of the string of the
> filename and not its contents. The contents are used for the
> computation by the alias.
>
> There are too many dereferencing operators for me.
>
> Thanks
>
> drrob1 wrote:
>
>
> ---Quote---
>> That's what I needed. Thanks
>>
>> vefatica wrote:
>> ---Quote---
>>> select echo (*.iso) > filespec.txt & echo crc32
>>> %@crc32[%@line[filespec.txt,0]] & del /q filespec.txt
>> ---End Quote---
> ---End Quote---
 
On Sat, 06 Feb 2010 18:28:20 -0500, drrob1 <> wrote:

|This batch file is not working
|
|batmd5:
| select /o:-d echo (*) >filespec
| set md5hash=%@md5[%@line[filespec,0]]
| IFF %md5hash EQ %@line[filespec,1] THEN
| echo Matched
| ELSE
| echo Not Matched
| ENDIFF
|
|When the md5hash is set, it is not set to the correct value. The
|correct value is displayed when I created the alias as described below
|by Vince.
|
|And I am getting an EOF condition when I try %@line[filespec,1]
|
|I suspect that the batch file is computing a hash of the string of the
|filename and not its contents. The contents are used for the
|computation by the alias.

What's in %@line[filespec,1]? I didn't see you put anything there.

I also don't understand why you're comparing a number (%md5hash) to something in
the file (filenames?).
--
- Vince
 
You may like this better combining Vince round about way with your
last effort simple DO < gotta love those do's and don'ts

setlocal
:: unset /q *
:: bdebugger /ne
select /o:-d echo (*) >>filespec

do r=0 to %@lines[filespec]
set md5hash=%@md5[f,%@line[filespec,%r]]
IFF %md5hash EQ %@md5[f,%@line[filespec,%r]] THEN
echo Matched
ELSE
echo Not Matched
ENDIFF
enddo
del /kq filespec
endlocal


----- Original Message -----
From: "Kachupp" <>
To: <[email protected]>
Sent: Sunday, February 07, 2010 1:58 PM
Subject: RE: [Support-t-1716] hash function question



> Try this
>
> setlocal
> unset /q *
> bdebugger /ne
> select /o:-d echo (*) >filespec
>
> set md5hash=%@md5[f,%@line[filespec,0]]
>
> IFF %md5hash EQ %@md5[f,%@line[filespec,0]] THEN
> echo Matched
> ELSE
> echo Not Matched
> ENDIFF
> endlocal
>
>
>
>
> ----- Original Message -----
> Sent: Sunday, February 07, 2010 12:28 PM
> Subject: RE: [Support-t-1716] hash function question
>
>
>
>
> ---Quote---
>> This batch file is not working
>>
>> batmd5:
>> select /o:-d echo (*) >filespec
>> set md5hash=%@md5[%@line[filespec,0]]
>> IFF %md5hash EQ %@line[filespec,1] THEN
>> echo Matched
>> ELSE
>> echo Not Matched
>> ENDIFF
>>
>> When the md5hash is set, it is not set to the correct value. The
>> correct value is displayed when I created the alias as described below
>> by Vince.
>>
>> And I am getting an EOF condition when I try %@line[filespec,1]
>>
>> I suspect that the batch file is computing a hash of the string of the
>> filename and not its contents. The contents are used for the
>> computation by the alias.
>>
>> There are too many dereferencing operators for me.
>>
>> Thanks
>>
>> drrob1 wrote:
>>
>>
>> ---Quote---
>>> That's what I needed. Thanks
>>>
>>> vefatica wrote:
>>> ---Quote---
>>>> select echo (*.iso) > filespec.txt & echo crc32
>>>> %@crc32[%@line[filespec.txt,0]] & del /q filespec.txt
>>> ---End Quote---
>> ---End Quote---
> ---End Quote---
>
>
>
 
On Sat, 06 Feb 2010 20:20:24 -0500, Kachupp <> wrote:

|setlocal
| :: unset /q *
| :: bdebugger /ne
| select /o:-d echo (*) >>filespec
|
| do r=0 to %@lines[filespec]
| set md5hash=%@md5[f,%@line[filespec,%r]]
| IFF %md5hash EQ %@md5[f,%@line[filespec,%r]] THEN
| echo Matched
| ELSE
| echo Not Matched
| ENDIFF
| enddo
|del /kq filespec
|endlocal

Is there some point to this? You read a filename from a file and set a variable
to the MD%hash of that file. Then you check to see if the variable contains the
MD5hash of the file (???). If it's just a test, fine, but it doesn't seem to do
anything useful.
--
- Vince
 
The way I see it its going to create a hash value for the file(s) selected
which will always
be true .. `it can't tell if its been tampered with`

If he wants to compare the hash values he will have to do it another way.

But you are right his method needs to focus on comparing hash values of his
.iso files
Example given below wouldn't be hard to change to `compare` values

----- Original Message -----
From: "vefatica"
To: Sent: Sunday, February 07, 2010 2:31 PM
Subject: RE: [Support-t-1716] hash function question



> On Sat, 06 Feb 2010 20:20:24 -0500, Kachupp <> wrote:
>
> |setlocal
> | :: unset /q *
> | :: bdebugger /ne
> | select /o:-d echo (*) >>filespec
> |
> | do r=0 to %@lines[filespec]
> | set md5hash=%@md5[f,%@line[filespec,%r]]
> | IFF %md5hash EQ %@md5[f,%@line[filespec,%r]] THEN
> | echo Matched
> | ELSE
> | echo Not Matched
> | ENDIFF
> | enddo
> |del /kq filespec
> |endlocal
>
> Is there some point to this? You read a filename from a file and set a
> variable
> to the MD%hash of that file. Then you check to see if the variable
> contains the
> MD5hash of the file (???). If it's just a test, fine, but it doesn't seem
> to do
> anything useful.
> --
> - Vince
>
>
>
>
 
> On Sat, 06 Feb 2010 20:20:24 -0500, Kachupp <> wrote:
>
> |setlocal
> | :: unset /q *
> | :: bdebugger /ne
> | select /o:-d echo (*) >>filespec
> |
> | do r=0 to %@lines[filespec]
> | set md5hash=%@md5[f,%@line[filespec,%r]]
> | IFF %md5hash EQ %@md5[f,%@line[filespec,%r]] THEN
> | echo Matched
> | ELSE
> | echo Not Matched
> | ENDIFF
> | enddo
> |del /kq filespec
> |endlocal
>
> Is there some point to this? You read a filename from a file and set a variable
> to the MD%hash of that file. Then you check to see if the variable contains the
> MD5hash of the file (???). If it's just a test, fine, but it doesn't seem to do
> anything useful.
An example would make this clearer
I have this file, we'll call it UbuntuHashes.txt. The contents are thus:

ubuntu-9.10-desktop-amd64.iso
dc51c1d7e3e173dcab4e0b9ad2be2bbf
ubuntu-9.10-desktop-i386.iso
8790491bfa9d00f283ed9dd2d77b3906

I have already downloaded the 2 iso files listed here. Each is meant to
fill a cd, so it is ~ 700 MB in size. I want to be able to select this
UbuntuHashes.txt file and have the md5 hash computed for the iso and
checked against the value provided by Canonical.

I did get this to work:
batchmd5.btm
set filespec=%@getfile[.]
set md5hash=%@md5[f,%@line[%filespec,0]]

IFF %md5hash EQ %@line[%filespec,1] THEN
echo Matched
ELSE
echo Not Matched
ENDIFF

One thing puzzles me though. The help file says that @getfile has been
replaced by the more powerful @getfolder. But I don't want a
foldername, I want a filename. I am also confused by the line that not
all folders are directories, as I use the term interchangably.

Thanks for your help; I needed a push in the right direction.

--rob
 
setlocal

unset /q *
: makes b-debugging clear with an empty environment
bdebugger /ne

set NixFileTXT=UbuntuHashes.txt
: you will need to be in the same folder as this file
: pushd "Where Ever The TXT file is"

select /o:-d echo (*) >>filespec

do r=0 to %@lines[filespec]

set md5hash=%@md5[f,%@line[filespec,%r]]
set uhash=%@line[%nixfiletxt,%r]

:: assuming from your post the filename and hashvalue are on the same line
:: word0 will be the iso filename, word1 will be the hash value

IFF %md5hash EQ %@word[1,%uhash] THEN
echo Matched
ELSE
echo Not Matched
ENDIFF
enddo
del /kq filespec
: popd
endlocal

----- Original Message -----
From: "drrob1" <>
To: <[email protected]>
Sent: Sunday, February 07, 2010 5:44 PM
Subject: RE: [Support-t-1716] hash function question



> An example would make this clearer
> I have this file, we'll call it UbuntuHashes.txt. The contents are thus:
>
> ubuntu-9.10-desktop-amd64.iso
> dc51c1d7e3e173dcab4e0b9ad2be2bbf
> ubuntu-9.10-desktop-i386.iso
> 8790491bfa9d00f283ed9dd2d77b3906


> One thing puzzles me though. The help file says that @getfile has been
> replaced by the more powerful @getfolder. But I don't want a
> foldername, I want a filename. I am also confused by the line that not
> all folders are directories, as I use the term interchangably.

Stay with @getfile the help doc is a little vague in places some anti aging
gel might fix that.
 
drrob1 wrote:
|
| An example would make this clearer
| I have this file, we'll call it UbuntuHashes.txt. The contents are thus:
|
| ubuntu-9.10-desktop-amd64.iso
| dc51c1d7e3e173dcab4e0b9ad2be2bbf
| ubuntu-9.10-desktop-i386.iso
| 8790491bfa9d00f283ed9dd2d77b3906
|
| I have already downloaded the 2 iso files listed here. Each is meant to
| fill a cd, so it is ~ 700 MB in size. I want to be able to select this
| UbuntuHashes.txt file and have the md5 hash computed for the iso and
| checked against the value provided by Canonical.
|
| I did get this to work:
| batchmd5.btm
| set filespec=%@getfile[.]
| set md5hash=%@md5[f,%@line[%filespec,0]]
|
| IFF %md5hash EQ %@line[%filespec,1] THEN
| echo Matched
| ELSE
| echo Not Matched
| ENDIFF

I will assume that the file listing filenames and hashcodes is short,
so that reading the file n! times (if it has n lines) is still
reasonable. Let the filename be passed as the only parameter to the
file below:

--- begin code ---
@echo off
setlocal
set hashlist=%@getfile[.]
do n = 0 to %@lines[%hashlist] by 2
set file=%@line[%hashlist,%n]
set hash=%@line[%hashlist,%@inc[%n]]
echo %@if[ %hash == %@md5[f,%file] ,OK ,BAD] %file
enddo
--- end code ---

If you have many lines to deal with, using DO's capability to process
consecutive lines of a file can be utilized:

--- begin code ---
@echo off
setlocal
set hashlist=%@getfile[.]
set next=file
do line in @hashlist
switch %next
case file
set file=%@line[%hashlist,%n]
set next=hash
case hash
set hash=%@line[%hashlist,%@inc[%n]]
echo %@if[ %hash == %@md5[f,%file] ,OK ,BAD] %file
set next=file
enddo
--- end code ---

|
| One thing puzzles me though. The help file says that @getfile has been
| replaced by the more powerful @getfolder. But I don't want a
| foldername, I want a filename.

I think this should have been a qualified statement, applicable only
when the desired item may be a folder instead of a file.


| I am also confused by the line that not
| all folders are directories, as I use the term interchangably.

In MS terminology, folders represent a collection of items, some of
which may be folders themselves, none of which need to have an
explicit mapping to directories in any of the disk volumes. For
example, the folder My Computer includes everything about the
computer, not just the contents of its individual disk volumes, yet
there is nowhere in the file system an entity named "My Computer".

--
HTH, Steve
 
Kachupp wrote:

> setlocal
>
> unset /q *
> : makes b-debugging clear with an empty environment
> bdebugger /ne
>
> set NixFileTXT=UbuntuHashes.txt
> : you will need to be in the same folder as this file
> : pushd "Where Ever The TXT file is"
>
> select /o:-d echo (*) >>filespec
>
> do r=0 to %@lines[filespec]
>
> set md5hash=%@md5[f,%@line[filespec,%r]]
> set uhash=%@line[%nixfiletxt,%r]
>
> :: assuming from your post the filename and hashvalue are on the same line
> :: word0 will be the iso filename, word1 will be the hash value
>
> IFF %md5hash EQ %@word[1,%uhash] THEN
> echo Matched
> ELSE
> echo Not Matched
> ENDIFF
> enddo
> del /kq filespec
> : popd
> endlocal
>
> ----- Original Message -----
> From: "drrob1" <>
> To: <[email protected]>
> Sent: Sunday, February 07, 2010 5:44 PM
> Subject: RE: [Support-t-1716] hash function question
>
>
>
>
> ---Quote---
>> An example would make this clearer
>> I have this file, we'll call it UbuntuHashes.txt. The contents are thus:
>>
>> ubuntu-9.10-desktop-amd64.iso
>> dc51c1d7e3e173dcab4e0b9ad2be2bbf
>> ubuntu-9.10-desktop-i386.iso
>> 8790491bfa9d00f283ed9dd2d77b3906
> ---End Quote---
>
>
> ---Quote---
>> One thing puzzles me though. The help file says that @getfile has been
>> replaced by the more powerful @getfolder. But I don't want a
>> foldername, I want a filename. I am also confused by the line that not
>> all folders are directories, as I use the term interchangably.
> ---End Quote---
> Stay with @getfile the help doc is a little vague in places some anti aging
> gel might fix that.

This is the final version that I think I'll stick w/ for a while.

setlocal
unset /q *
: bdebugger
set filespec=%@getfile[.]

: you will need to be in the same folder as this file
:: assuming from your post the filename and hashvalue are on the
same line
:: word0 will be the iso filename, word1 will be the hash value

do r=0 to %@lines[filespec]
set aline=%@line[filespec,%r]
set md5hash=%@md5[f,%@word[0,%aline]]
IFF %md5hash EQ %@word[1,%aline] THEN
echo Matched
ELSE
echo Not Matched
ENDIFF
enddo
endlocal

Again, thanks guys
 
This removes the need for an external file and allows you to display
results for multiple files.

select echo (*.txt) | for %f in (@con:) echo crc32 of %f is %@crc32[%f]

-Scott

drrob1 <> wrote on 02/06/2010 03:44:26 PM:


> That's what I needed. Thanks
>
> vefatica wrote:
>
>
> ---Quote---
> > On Sat, 06 Feb 2010 11:45:11 -0500, drrob106 <> wrote:
> >
> > |I think you misunderstood my question. I download .iso files
frequently

> > |and would like to check their hashes against published info to make
sure

> > |that a GB file is correct. I am NOT looking to compare 2 files.
> >
> > It isn't pretty, but this might do what you want.
> >
> > select echo (*.iso) > filespec.txt & echo crc32 %@crc32[%
> @line[filespec.txt,0]] & del /q filespec.txt
> ---End Quote---
>
>
>
 
samintz wrote:
| This removes the need for an external file and allows you to display
| results for multiple files.
|
| select echo (*.txt) | for %f in (@con:) echo crc32 of %f is
| %@crc32[%f]

Or:

select echo (*.txt) | for %f in (@con:) pdir /(r "is the CRC32 hash of" fpn)
%f

However, this does not help the OP - the external file is part of his
download, provided to validate download accuracy.
--
Steve
 

Similar threads

Back
Top