From: Niklas Frykholm Date: 2001-11-13T18:50:48+09:00 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. ;) // Niklas