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(/([^\aeiouy])/,"\\1o\\1")
end
print str