gstring 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gstring.rb +125 -5
  3. data/lib/gstring/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ced11932da70666e5f25d7becccc40f3898e28f3
4
- data.tar.gz: a5c4f7ed36e54aefbb0b84453ffc17bc64727e4d
3
+ metadata.gz: c8c020dd94769068e85f9925353e9d710708b11d
4
+ data.tar.gz: 062eea3313e009d9ed8136f2c329265b51d8083a
5
5
  SHA512:
6
- metadata.gz: d6bddc4f25b2b37408cec2a975adb7a9a70f7789dd46d9b1994b171fe6644f9efdeb8d6c6d03ec5328a77b68d3e2af1515f55834f7e2b17f10e07ce167977c06
7
- data.tar.gz: 53a85b0370b2cc4c5d7fd946a303477c4c9485fcb5b5498d531db1e3b48123523bcb7a27ba7e207b58ec9ce0fbf74231bf45195eb9c71f37be6c375cd8e598d0
6
+ metadata.gz: 37f685b2bc067c0a7305633231853e2fcacaca6f47c188db6c60eb4ea77a0787b59ce11a190ebee8841e97c5f84cfa829bcf39d90107fd002e9d37a26002266a
7
+ data.tar.gz: c4546345771fbbd250db4c7a977f2dc25a91afc8d753e815ea28f493d4acf8e579cf3423c855a0b74b6cad941c040c126f860e6ab52ecab5fac72263953a3a25
@@ -400,13 +400,133 @@ class String
400
400
  return true
401
401
  end
402
402
 
403
+ def duplicates
404
+ str = self.sort
405
+ set = BitSet.new
406
+ rtn = ""
407
+ last_chr = ""
408
+ str.each_char do |ch|
409
+ if last_chr == ch
410
+ unless set.include? ch
411
+ rtn += ch
412
+ end
413
+ set.add! ch
414
+ end
415
+ last_chr = ch
416
+ end
417
+ return rtn
418
+ end
419
+
420
+ #ROT_STRING = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?/>.<,"\':;|\\}]{[+=_-)(*&^%$#@!`~Ω≈ç√∫˜µ≤≥÷åß∂ƒ©˙∆˚¬…æœ∑´®†¥¨ˆøπ“‘«`¡™£¢∞§¶•ªº–≠¸˛Ç◊ı˜Â¯˘¿ÅÍÎÏ˝ÓÔÒÚÆŒ„´‰ˇÁ¨ˆØ∏”’»`⁄€‹›fifl‡°·‚—±'
421
+
422
+ ROT_STRING = '{Copyright© 2016_BRYAN-cOLVIn=al|.®¡GHTS/4ME},+bd¯˘¿ÅÍe^%$f∛jΆ¥w¼∜x7Ï˝ÓÔk”’»⁄€‹×›fifl‡°·‚KPøπ“‘s½u!~Ω≈çzD∮5vF∂«`™£WJŒ„‰ˇÁ¨ˆØ∏3QℵU(*&#@√∫µ≤≥÷åßXZmqƒ˙∆˚¬…æœ∑´89?><"\':;\\][)¢∞§¶•ªº–≠¸˛Ç◊ı˜ÒÚÆ—±'
423
+ ROT_LEN = ROT_STRING.length
424
+ @@rot_hash = {}
425
+ ii = 0
426
+ ROT_STRING.each_char do |ch|
427
+ @@rot_hash[ch] = ii
428
+ ii += 1
429
+ end
430
+
431
+ def each_ord
432
+ unless block_given?
433
+ enu = Enumerator.new do |y|
434
+ self.each_char do |ch|
435
+ y << ch.ord
436
+ end
437
+ end
438
+ return enu
439
+ end
440
+ self.each_char do |ch|
441
+ yield ch.ord
442
+ end
443
+ end
444
+
445
+ def rehash # more consistent hash method
446
+ sum = 0
447
+ tr = 4294967296
448
+ rL = Random.new(self.length)
449
+ sum = rL.rand(tr)
450
+ self.each_char do |ch|
451
+ rt = Random.new(ch.ord)
452
+ sum += rt.rand(tr)
453
+ sum ^= rL.rand(sum)
454
+ end
455
+ return sum & (tr-1)
456
+ end
457
+
458
+ def rot_crypt(pswd="Standard Password should never be used!")
459
+ raise "illegal password" if pswd.empty?
460
+ rtn = ""
461
+ ptr = 0
462
+ rnd = Random.new(pswd.rehash)
463
+ len = pswd.length
464
+ self.each_char do |ch|
465
+ ss = @@rot_hash[ch]
466
+ if ss.nil? # make no subs
467
+ rtn += ch
468
+ else
469
+ # pos = (ch.ord + pswd[ptr].ord + rnd.rand(ROT_LEN)) % ROT_LEN
470
+ pos = (ss + pswd[ptr].ord + rnd.rand(ROT_LEN)) % ROT_LEN
471
+ rtn += ROT_STRING[pos]
472
+ end
473
+ ptr += 1
474
+ ptr = 0 if ptr >= len
475
+ end
476
+ return rtn
477
+ end
478
+
479
+ def rot_decrypt(pswd="Standard Password should never be used!")
480
+ raise "illegal password" if pswd.empty?
481
+ rtn = ""
482
+ ptr = 0
483
+ rnd = Random.new(pswd.rehash)
484
+ len = pswd.length
485
+ self.each_char do |ch|
486
+ ss = @@rot_hash[ch]
487
+ if ss.nil? # make no subs
488
+ rtn += ch
489
+ else
490
+ pos = @@rot_hash[ch] # got back the number
491
+ pos = pos - pswd[ptr].ord - rnd.rand(ROT_LEN)
492
+ pos = pos % ROT_LEN
493
+ # rtn += pos.chr(Encoding::UTF_8)
494
+ rtn += ROT_STRING[pos]
495
+ end
496
+ ptr += 1
497
+ ptr = 0 if ptr >= len
498
+ end
499
+ return rtn
500
+ end
501
+
502
+ ###### DOES NOT WORK WITH RAILS ###################
503
+
403
504
  # ... add new meaning to what would have raised an error ...
404
505
  # now means case insensitive compare
405
- alias_method :old_string_rgx_cmp, :=~
406
- def =~(str)
407
- return old_string_rgx_cmp(str) unless str.class==String
408
- self.downcase == str.downcase
409
- end
506
+ # alias_method :old_string_rgx_cmp, :=~
507
+ # def =~(str)
508
+ # return old_string_rgx_cmp(str) unless str.class==String
509
+ # self.downcase == str.downcase
510
+ # end
511
+
512
+ ####################################################
513
+
514
+ # replace with this ...
515
+ def cmp(other)
516
+ self <=> other
517
+ end
518
+
519
+ def cmpi(other)
520
+ self.upcase <=> other.upcase
521
+ end
522
+
523
+ def eqli?(other)
524
+ self.upcase == other.upcase
525
+ end
526
+
527
+ def equali?(other)
528
+ self.upcase == other.upcase
529
+ end
410
530
 
411
531
  # generator does not need an instance
412
532
  def self.random_password(chars=8, special="_-#!~@$%^*+=?:")
@@ -1,3 +1,3 @@
1
1
  module Gstring
2
- VERSION = "3.0.0"
2
+ VERSION = "4.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gstring
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Colvin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: setfu