------ art_1606_15254998.1186759855782 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Right, probably should have told you my AIM name if I asked you to talk to me there. I'm LastGreyMaiden on AIM. greymaiden on GoogleChat. Braaaaaiiiiinsss. . . .sigh. On 8/10/07, Jamie Lynn O'Marr <greymaiden / gmail.com> wrote: > > This is actually a timely question; I was about to start working on the > same problem! > > I'm a Ruby nuby, and as practice I decided that my first project would be > a suite of old school cryptography encryption/decryption software. (Later > to be web-ified with Rails so anyone can use it on the web) > > So this isn't exactly an answer to your question, but it is a way to > optimize your decryption: > > Substitution cyphers are easiest to solve with a frequency analysis. (The > most common letters in the English language are 'E' 'T' and 'A' in that > order) Of course, the utility of this method increases with the length of > the cyphertext, so it may not be useful for very short (one word) messages > but is very useful for longer blocks of text (two or three sentences or > more). > > Rather than computing all possible cyphers every time, you could make each > calculation dependent on a frequency analysis. So you count the number of > times each letter appears in the cyphertext, then try substituting the > letter that corresponds to the frequency. It is possible you may have to > run through several dozen combinations before you hit on the right one, but > it should be much faster than just calculating every single possible > combination. Rather than a random assignment of letter combinations, you > make the choice of combinations dependent on the frequency analysis. It > will require user input each time (puts 'Does this make sense? (y/n)') in > order to determine if the decryption actually worked (unless you're going to > include a syntax library to check it against, and if you do that, please > tell me how you do it!). I hope eventually to allow the user to adjust the > frequency analysis themselves, because the human brain can spot patterns > that pure statistics can't. . .but that's a little more complicated. > > I wish I had some code for you, but like I said, I was just about to start > working on this myself. On the other hand, if you want some Ruby code for > substitution ENcryption, I'm putting the finishing touches on that right > now. Sorry I'm not faster, but I'm learning Ruby in between raising a > toddler, gestating a new kid, and trying to get into law school ;) > > Hit me up on AIM if you want to talk about old school cryptography. I'm > not much of a Ruby coder yet, but I know a lot about old school cryptography > :) > > Jamie Lynn > AKA greymaiden > over. > > > > On 8/10/07, Aric Campbell <ajcampbell0128 / yahoo.com> wrote: > > > > I am trying to find every possible combination of the letters of the > > alphabet to create a file by a program to solve simple replacement ciphers. > > There shouldn't be any repeat of letters in the combination (i.e. a can > > only occur once in a given combination). > > > > I had thought of using the code below to get every possible combination > > and, even though it contains duplicate letters in the combinations it > > generates, I was going to prune those out. The problem is that it would take > > a very considerable number of years before the program finishes. Anyone know > > of an algorithm that I could use to generate the possibilities in a more > > timely manner? > > > > > > > > class Value > > def initialize val ' > > @value al > > end > > > > def rhs > > if rhs.class ! elf.class > > return false > > > > end > > rhs.value self.value > > end > > > > def next > > if @value 'z' > > self.reset > > else > > @value value.next > > end > > end > > > > def reset > > @value a' > > end > > > > def value > > @value > > end > > > > end > > > > > > > > > > class Set > > def initialize > > @buffer ] > > 26.times {@buffer << Value.new} > > end > > > > def value > > @buffer > > > > temp ] > > > > @buffer.each{|a| temp << a.value} > > > > temp > > end > > > > def exausted? > > @buffer.each do |a| > > if a.value ! z' > > return false > > end > > end > > return true > > end > > > > def next > > cursor > > > > > > while true > > if @buffer.last(cursor)[0].value 'z' > > > > @buffer.last(cursor)[0].next() > > cursor + > > @buffer.last(cursor)[0].next() > > > > else > > @buffer.last(cursor)[0].next() > > break > > end > > end > > self.value > > > > end > > > > end > > > > > > ################################################################# > > ################################################################# > > > > > > s et.new > > f pen "sets.out",'w' > > > > f << s.value > > > > > > while s.exausted? false > > f << s.next << "\n" > > end > > > > > > > > > > --------------------------------- > > Be a better Globetrotter. Get better travel answers from someone who > > knows. > > Yahoo! Answers - Check it out. > > > > ------ art_1606_15254998.1186759855782--