PC Nerd Posted December 17, 2008 Share Posted December 17, 2008 Hi, I'm working with sending md5checksums of different strings and files to a server to validate they downloaded correctly, and I wanted to (more of an excersise than anythign else) try and reduce what I'm sending. Instead of sending 10 checksums across the net, I wanted to eg. send one checksum which "represents" all the data. Is: $ck1 = md5("string"); $ck2 = ... $ck3 = ... $ck4 = ... $ck5 = ... md5($ck1+$ck2+$ck3+$ck4+$ck5); // Is this line a "valid" representation of the previous 5 checksums or is there a more standard method? Thanks Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted December 17, 2008 Share Posted December 17, 2008 When you say reduce what you are sending, do you mean you want to cut down on the actual size (bytes) or the # of variables that have to be passed? If you just want to reduce the number of variables, try putting all the md5 sums in an array. Then you can reference the array and pull out any m5d sum or all of them. I don't think md5($ck1+$ck2+$ck3+$ck4+$ck5); is a very good idea. Manly because this will return a different md5 if the same files are sent, but in a different order. md5($ck1+$ck2+$ck3+$ck4+$ck5) != md5($ck5+$ck4+$ck3+$ck2+$ck1); You could always do something like md5($ck1) + md5($ck2) and have it work for your application, but it's not truly a checksum if you do that. Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted December 17, 2008 Share Posted December 17, 2008 $md5[] = whatever $md5[] = whatever2 etc $big = ''; foreach ($md5 as $value) { $big = $big . $value; } $out = md5($big); Chris Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 17, 2008 Share Posted December 17, 2008 As long as the md5's are in the same order, your solutions should work just fine. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 18, 2008 Author Share Posted December 18, 2008 Ok - thanks all * and to answer the first question - it was both a task of reducing the numebr of variables and the number of bytes. ultimately - a checksum of all the data is less than individual checksums of each data entry Thanks - Sovled Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.