SHOW:
|
|
- or go back to the newest paste.
| 1 | require 'digest' | |
| 2 | ||
| 3 | mySha1 = Digest::SHA1.new | |
| 4 | ||
| 5 | if (ARGV.index('-h')) && (ARGV[ARGV.index('-h')+1] != nil) # check if '-h' switch is in ARGV[] and the following index is non-null.
| |
| 6 | - | if File.exist?(ARGV[ARGV.index('-h')+1]) #next check if that following index is an existing file.
|
| 6 | + | myFile = ARGV[ARGV.index('-h')+1]
|
| 7 | - | File.open(ARGV[ARGV.index('-h')+1]) do|file|
|
| 7 | + | if File.exist?(myFile) # next check if that file exists. |
| 8 | File.open(myFile]) do|file| | |
| 9 | myBuff = '' | |
| 10 | while not file.eof | |
| 11 | file.read(512, myBuff) | |
| 12 | mySha1.update(myBuff) | |
| 13 | end | |
| 14 | print mySha1 | |
| 15 | end | |
| 16 | else | |
| 17 | print 'Invalid file specified' | |
| 18 | end | |
| 19 | end |