I need to convert this code written in Ruby to other language

Hello,

I m actually a PHP, C# programmer and thinking of getting my hands to
Ruby as well. I have 3 lines of codes that is in ruby which I need
equivalent in c#. As the question is related to ruby, I thought this
place would be a good one to post.

The code

key =“asdfsdfk234kjasdfkj23sdkfj”
final_key = “\0” * 16
key.length.times do |i|
final_key[i%16] = (final_key[i%16].ord ^ key[i].ord).chr
end
puts final_key

Any help will highly be appreciated
Thanks

On Wed, Nov 27, 2013 at 4:11 PM, Sabin C. [email protected]
wrote:

Hello,

I m actually a PHP, C# programmer and thinking of getting my hands to
Ruby as well. I have 3 lines of codes that is in ruby which I need
equivalent in c#. As the question is related to ruby, I thought this
place would be a good one to post.

The code

I don’t know C#, but I can try to explain what this does, so maybe you
can translate it yourself:

key =“asdfsdfk234kjasdfkj23sdkfj”

Initialize a string with those chars.

final_key = “\0” * 16

Initialize a string with 16 zeros (the byte 0)

key.length.times do |i|

once for each char in the key string:

final_key[i%16] =

set the character at position i modulus 16 (so you go round and round
along the string final_key) to the value calculated like so:

[…] (final_key[i%16].ord ^ key[i].ord).chr

take the byte value of that position in the string, and xor with the
byte value of the current position in the key. ord returns the byte
value of a char, and chr returns the char corresponding to a integer
value, so after xoring, you take the char that corresponds to that
value and place it in the string.

end
puts final_key

print the resulting string.

Jesus.