[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: I need to convert this code written in Ruby to other language
From:       Jesús_Gabriel_y_Galán <jgabrielygalan () gmail ! com>
Date:       2013-11-27 16:37:18
Message-ID: CAPg0dkwva=btnweyi5HkmAFFnUS4x684sz+-FARFST4a6HojiA () mail ! gmail ! com
[Download RAW message or body]

On Wed, Nov 27, 2013 at 4:11 PM, Sabin Chhetri <lists@ruby-forum.com> 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.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic