[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

string parity module

snacktime

8/12/2006 6:42:00 AM

Anyone know of an existing module for settings odd/even/space parity on strings?

2 Answers

snacktime

8/13/2006 6:24:00 AM

0

If anyone has any input on how to write this better or a better way to
implement it let me know. In any case here is a class for setting
odd/even/space parity on strings.

class StringParity

def initialize
even_bits = "\0"
odd_bits = "\200"
codes = ""
ascii = []

@even_parity = []
@odd_parity = []
@space_parity = []

8.times do
even_bits << odd_bits
odd_bits = even_bits.clone
odd_bits.tr!("\0\200","\200\0")
end


(0..255).collect {|i| ascii << i}
codes = ascii.pack('C*')
(0..127).collect { |i| @space_parity[i + 128] = codes[i] }
@even_parity = (0..codes.length-1).collect { |i| codes[i] ^ even_bits[i] }
@odd_parity = (0..codes.length-1).collect { |i| codes[i] ^ odd_bits[i] }
end

def setEvenParity(str)
new = []
str.each_byte {|b| new << @even_parity[b]}
new.pack("C*")
end

def setOddParity(str)
new = []
str.each_byte {|b| new << @odd_parity[b]}
new.pack("C*")
end

def setSpaceParity(str)
new = []
str = str.unpack("C*")
str.collect {|b| new << (@space_parity[b] || b)}
new.pack("C*")
end

end

s = StringParity.new
str = "testing12345678910()*&^%@!~"

str = s.setEvenParity(str)
print "#{str}\n"

str = s.setSpaceParity(str)
print "#{str}\n"

str = s.setOddParity(str)
print "#{str}\n"

str = s.setSpaceParity(str)
print "#{str}\n"

John

4/25/2009 10:31:00 AM

0

Bill Swears <wswears@gci.net> wrote:

>nobody wrote:
>> Jacey Bedford <lookinsig@nospam.invalid> wrote:
>>
>>> Michelle I believe you maintain the FAQ and Zeborah posted it regularly.
>>> Is that correct?
>>>
>>> So do we have volunteers to post the FAQ every couple of weeks and the
>>> newcomers FAQ whenever necessary?
>>>
>>> It should be someone organised enough to remember. which is... err...
>>> probably not me.
>>>
>>> Jacey
>>
>> Jacey, why have one person post the faq every couple weeks when many
>> people could add a link to it in their sig?
>>
>I'm not Jacey, but the reason generally is that Sigs aren't much
>attended, and people want to alter theirs periodically. I for one,
>don't often look at sigs unless somebody points theirs out.
>
>Bill

Maybe it's a bad idea, I just thought that if "regulars" put a link to
the FAQ in their sigs, it would show up often enough for new posters
to find it.

I use an nntp client (Forte Agent) that doesn't download the entire
previous content of a group to which I've subscribed unless I allow it
to sit there doing that for several hours. As a result, a FAQ that is
posted every couple weeks... won't be visible to me for a couple of
weeks or so.

Whatever, it's just a suggestion.

--
http://fictionfromnobody.bl...