On Thu, May 8, 2008 at 11:10 AM, globalrev <skanemupp / yahoo.se> wrote:
> On 8 Maj, 15:12, Heesob Park <pha... / gmail.com> wrote:
>> Hi,
>>
>>
>>
>> globalrev wrote:
>> > ty all for the help. haesob park did what iw anted.
>>
>> > this is the program i wrote, it  is an encrypter/decrypter for the
>> > robbers language(r�arspr�et in swedish), its from the book Kalle
>> > Blomkvist by late and very famous author Astrid Lindgren.
>> > you add o + the consonant, nothing is done to vowels.
>> > so d becomes dod, a is just a.
>>
>> > dad is therefore dodadod, super is sosupoperor etc.
>>
>> > puts "Enter sentence to encrypt: "
>> > str = gets
>>
>> > enc = ""
>> > for x in (0..str.length()-1)
>> >   if str[x].chr =~ /[qwrtpsdfghjklzxcvbnm]/
>> >       enc = enc + str[x].chr + "o" + str[x].chr
>> >   else
>> >       enc = enc +str[x].chr
>> >   end
>> > end
>>
>> > print enc
>>
>> > puts "Enter code to decrypt: "
>> > code = gets
>>
>> > x = 0
>> > dec = ""
>> > while (x<code.length())
>> >   dec = dec + code[x].chr
>> >   if code[x].chr =~ /[qwrtpsdfghjklzxcvbnm]/
>> >     x = x + 2
>> >   end
>> >   x = x + 1
>> > end
>>
>> > print dec
>>
>> > i then changed to !~ just like haesob said but if i do /aeiouy / it
>> > doesnt react to space " ". how do i get it to treat " " as "a"?
>>
>> You can do with like this:
>> if str[x].chr !~ /[\saeiouy]/
>>
>> BTW, your encryption equals to
>> str.gsub(/([^\saeiouy])/,"\\1o\\1")
>>
>> Regards,
>> Park Heesob
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> that doesnt seem to work, it repeats the sma ething alot of times
> befre next letter.
>
> if this is what u meant(why did u add the "s" ?):
> for x in (0..str.length()-1)
>   str = str.gsub(/([^\saeiouy])/,"\\1o\\1")
> end
> print str

I'll repeat.  With /[^aeiouy]/ you will get a true for _any_ character
with byte number between 0 and 255 that is not [<whitespace>aeiouy],
including punctuation marks, the capital vowels, and other characters
ala..

"Hello, \n\rtherE!" would become "HoHelollolo,o,\no\n\ro\rtothoherorEoE!o!"

...and also includes everything above 126 and below 32 which is fine
if that's what you want.  Of course, any key would work, it doesn't
have to be just consonants, so I guess the point is sort of moot; just
thought I would mention it.

Todd