From: "Hal E. Fulton" Date: 2001-11-13T19:22:37+09:00 Subject: [ruby-talk:25001] Re: Mapping sequential strings to random strings: How would you do this? ----- Original Message ----- From: Niklas Frykholm To: ruby-talk ML Sent: Tuesday, November 13, 2001 3:50 AM Subject: [ruby-talk:24995] Re: Mapping sequential strings to random strings: How would you do this? > [Hal E. Fulton] > > But I don't want the names to be "guessable" -- i.e., > > doc001.html, doc002.html, and so on. > > > > I'm thinking of keeping some kind of mapping between the > > original names and "scrambled" file names. For example, > > the files might be named xjhfkros.html, 7glcm3lg.html, and > > so on. > ... > > Constraints I'd like to see are: > > 1. Fixed-length scrambled strings; > > 2. True one-to-one mapping > > 3. "Reasonable" (printable) characters only > > 4. Non-obvious mapping > > What about > > require 'md5' > secret = 'aljfaweru923jfjkasfljas' > > MD5.md5('doc001.html' + secret).hexdigest + '.html' > > Replace the value of secret with some random string known only to you. > It fulfills 1, 2, 3 and 4. (Well it doesn't fulfill 2 in theory, but > collisions are extremely rare. In fact, if you would find a collision, > you would have 'broken' MD5. You could publish it and become famous. ;) Yes, that works well... thanks very much. I had quite forgotten that md5 was around... thought it was something I had to download. Now, I wonder if there is a way to make the strings shorter? ;) Hal