From: Paul Golea Date: 2009-02-23T18:44:24+09:00 Subject: Cyclic redundancy check (CRC32) of a file Hello, I try to calculate the CRC32 of a file with a script ruby, but I does not obtain the good result by comparison with many of the other software which already make this (in other programming language...), for example: http://www.codeproject.com/KB/recipes/crc32.aspx I use this script : _____________________ require 'zlib' filetest = File.read 'image.jpg' puts Zlib.crc32(filetest, 0).to_s(16).upcase _____________________ The result looks like well of an CRC32 but it is never good... I also try a pure ruby implementation with this code but it makes exactly the zlib.crc32 result... : _____________________ def crc32(c) n = c.length r = 0xFFFFFFFF n.times do |i| r ^= c[i] 8.times do if (r & 1)!=0 r = (r>>1) ^ 0xEDB88320 else r >>= 1 end end end r ^ 0xFFFFFFFF end filetest = File.read 'image.jpg' puts crc32(filetest).to_s(16).upcase _____________________ Thank you very much to the person who will have the solution of my problem. -- Posted via http://www.ruby-forum.com/.