Wish list for 2.0

In ref to http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/31099

A deletew or rmwhite where it deletes all the white space from a string
If you can use delete(/s) or something PLEASE let me know! :slight_smile:

Becker

Hi,

···

In message “Re: Wish list for 2.0” on Tue, 28 Sep 2004 12:44:07 +0900, STEPHEN BECKER I V Becker004@gmail.com writes:

A deletew or rmwhite where it deletes all the white space from a string
If you can use delete(/s) or something PLEASE let me know! :slight_smile:

str.delete(" ")

						matz.

A deletew or rmwhite where it deletes all the white space from a string
If you can use delete(/s) or something PLEASE let me know! :slight_smile:

str = " abc def \n ghi jkl "
str.gsub!(/\s+/,'')
p str
# prints "abcdefghijkl"

You can define this as your own String#deletew method easily enough if you
need to use it over and over again:

class String
  def deletew!
    gsub!(/\s+/,'')
  end
  def deletew
    dup.deletew!
  end
end

Regards,

Brian.

does that work for end lines in the middle of a string? or a tab? I
mean all white space…

···

On Tue, 28 Sep 2004 12:56:21 +0900, Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

In message “Re: Wish list for 2.0” > on Tue, 28 Sep 2004 12:44:07 +0900, STEPHEN BECKER I V Becker004@gmail.com writes:

A deletew or rmwhite where it deletes all the white space from a string
If you can use delete(/s) or something PLEASE let me know! :slight_smile:

str.delete(" ")

                                                   matz.

STEPHEN BECKER I V wrote:

does that work for end lines in the middle of a string? or a tab? I
mean all white space…

What’s wrong with str.gsub!(/\s/, ‘’), or similar ?

(I clicked looking for a wish list. I can’t think of anything either…)

···


Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces

Hi,

···

In message “Re: Wish list for 2.0” on Tue, 28 Sep 2004 13:01:24 +0900, STEPHEN BECKER I V Becker004@gmail.com writes:

does that work for end lines in the middle of a string? or a tab? I
mean all white space…

str.delete(" \n\t")

if you wish.

						matz.

Perhaps String#delete could take a regex as well?

  str.delete /\s/

Gavin

···

On Tuesday, September 28, 2004, 2:40:02 PM, Yukihiro wrote:

Hi,

In message "Re: Wish list for 2.0" > on Tue, 28 Sep 2004 13:01:24 +0900, STEPHEN BECKER I V <Becker004@gmail.com> writes:

>does that work for end lines in the middle of a string? or a tab? I
>mean all white space..

  str.delete(" \n\t")

if you wish.

Hi,

···

In message “Re: Wish list for 2.0” on Tue, 28 Sep 2004 15:45:29 +0900, Gavin Sinclair gsinclair@soyabean.com.au writes:

Perhaps String#delete could take a regex as well?

str.delete /\s/

Interesting idea. What if pattern match overwrap, e.g.

str = “aabab”
str.delete(/a./)

? Should it work as str.gsub(pat, “”) ?

						matz.

That makes sense. Might as well implement it like that so it can be
documented as such.

Gavin

···

On Tuesday, September 28, 2004, 5:45:08 PM, Yukihiro wrote:

>Perhaps String#delete could take a regex as well?
>
> str.delete /\s/

Interesting idea. What if pattern match overwrap, e.g.

  str = "aabab"
  str.delete(/a./)

? Should it work as str.gsub(pat, "") ?

Maybe model the behavior after #scan, so that it deletes the matches that scan
would have found. This way we can get very flexible deletion in case
captures are being used.

I propose #delete to erase those fragments that #scan matches.

irb(main):011:0> 'a12bc34de56fg78hi'.scan(/(\d).{2,}?(\d)/)
=> [["1", "3"], ["4", "5"], ["6", "7"]]
irb(main):012:0> 'a12bc34de56fg78hi'.scan(/\d.{2,}?\d/)
=> ["12bc3", "4de5", "6fg7"]
irb(main):013:0>

Lets change above 2 scan statements into delete

irb(main):011:0> 'a12bc34de56fg78hi'.delete(/(\d).{2,}?(\d)/)
=> "a2bcdefg8hi"
irb(main):012:0> 'a12bc34de56fg78hi'.delete(/\d.{2,}?\d/)
=> "a8hi"
irb(main):013:0>

Ok.. this is not the most obvious example.. but I hope you get the point.
Otherwise please ask :slight_smile:

···

On Tuesday 28 September 2004 11:26, Gavin Sinclair wrote:

On Tuesday, September 28, 2004, 5:45:08 PM, Yukihiro wrote:
> >Perhaps String#delete could take a regex as well?
> >
> > str.delete /\s/
>
> Interesting idea. What if pattern match overwrap, e.g.
>
> str = "aabab"
> str.delete(/a./)
>
> ? Should it work as str.gsub(pat, "") ?

That makes sense. Might as well implement it like that so it can be
documented as such.

--
Simon Strandgaard

how about isprime, nextprime, preprime?

Heck, why not a Numeric#factors (it should work on Bignums too)...

Or how about just something that gives you the zeros of the zeta
function?

Or...

-- MarkusQ

···

On Thu, 2004-09-30 at 11:30, STEPHEN BECKER I V wrote:

how about isprime, nextprime, preprime?

STEPHEN BECKER I V <Becker004@gmail.com> wrote in message news:<3703ec2d04093011303c14c44b@mail.gmail.com>...

how about isprime, nextprime, preprime?

It's not something one would use extremely often, now would it?
Anyway, aren't those already in a math module or something?

Markus wrote:

···

On Thu, 2004-09-30 at 11:30, STEPHEN BECKER I V wrote:

how about isprime, nextprime, preprime?

Heck, why not a Numeric#factors (it should work on Bignums too)...

thats easy. Just guess the correct factorization and validate. Only need to find my non-deterministic turing machine. ... I must have put it somewhere ....

Brian
--
Brian Schröder
http://ruby.brian-schroeder.de/

It's not something one would use extremely often, now would it?
Anyway, aren't those already in a math module or something?

Right, similar methods are provided as part of Evan Webb's MBignum lib
http://fallingsnow.net/ruby/ruby-mbignum-0.5/doc/index.html

code at:
http://fallingsnow.net/ruby/ruby-mbignum-0.5/

···

--
--- vruz

no they are not. They are in the Mbignum but that is not standard i
guess. I think it would be useful, I think if you had the RSA key
producers built in it would help ruby become more popular with
security program. or at least crypto stuff.

···

On Fri, 1 Oct 2004 09:40:07 +0900, Vincent Foley <vfoley@gmail.com> wrote:

STEPHEN BECKER I V <Becker004@gmail.com> wrote in message news:<3703ec2d04093011303c14c44b@mail.gmail.com>...

> how about isprime, nextprime, preprime?

It's not something one would use extremely often, now would it?
Anyway, aren't those already in a math module or something?

no they are not. They are in the Mbignum but that is not standard i
guess. I think it would be useful, I think if you had the RSA key
producers built in it would help ruby become more popular with
security program. or at least crypto stuff.

You are right, MBignum is not standard, still very useful for the
purposes you've mentioned.
Someone proposed to make it standard some time ago but not
sure how that turned how at last.
In any case, the best answer can be provided by the author himself.

cheers,
                   vruz

Ruby 1.8.x has openssl built in:

  require 'openssl'
  k = OpenSSL::PKey::RSA.new(256) # generate 256 bit RSA private key
  puts k.p, k.q, k.n # two primes and their product
  p k.p * k.q == k.n # true

OpenSSL's bignum library is wrapped which includes a number of important
mathematical operations. See
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3367 for an
example of them in action, generating RSA private key parameters from p, q
and e.

The attached Ruby snippets will:
1. take a PEM public key file and extract n and e
2. take n, e and factors of n (p, q) and create a PEM private key file

All you then need is something like mpqs4linux to break RSA keys. You can do
a 256-bit key in about 45 minutes on a PIII-933MHz without needing to
understand any maths at all :slight_smile:

Regards,

Brian.

crackrsa1.rb (365 Bytes)

crackrsa2.rb (1.18 KB)

···

On Sat, Oct 02, 2004 at 09:56:45AM +0900, STEPHEN BECKER I V wrote:

no they are not. They are in the Mbignum but that is not standard i
guess. I think it would be useful, I think if you had the RSA key
producers built in it would help ruby become more popular with
security program. or at least crypto stuff.