Ruby on Rails Saturday, February 4, 2012

John Merlino wrote in post #1044105:
> The % is modulus (remainder) operator and ^ is bitwise. In this
> context, we take a file, and go through each character and encrypt it.
> But why are the ^ and % operators used here:
>
> def encrypt(reader, writer)
> key_index = 0
> while not reader.eof?
> clear_char = reader.getc
> encrypted_char = clear_char ^ @key[key_index]
> writer.putc(encrypted_char)
> key_index = (key_index + 1) % @key.size
> end
> end
>
> thanks for response

The use of XOR is a common operation in cryptography. I'm not sure how
it all exactly works, but I have serious doubts about the security of
this particular encrypt method. I would highly recommend using an actual
encryption library, and never try to do it yourself. That is if you want
any sense of real security at all.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment