roob noob wrote in post #1061056:
> I used an instance variable for @ciphertext because I was getting it
> with @crypt.instance_variable_get("@ciphertext") but then I realized I
> can do it in a much nicer way.

The method should simply return the encrypted string and do nothing 
else. Like I said earlier: Don't misuse instance variables to pass 
values around. This is not only ugly and cumbersome but also prone to 
error, because the method then becomes dependend on some outer 
variables. What if the value is accidently changed by another method? 
This will break your code, and you'll have a hard time finding the 
reason.

We've already discussed this in an earlier thread:
http://www.ruby-forum.com/topic/4246662#new

I don't know how you've come to adept this programming style, but you 
should get rid of it right away. This also applies to the 
"instance_variable_get". While this does work, it's very bad style and 
more of a hack. Outer objects are supposed to use the getters and 
setters and not fumble with the actual variables inside the object.



> can you please confirm that each version works correctly for you on your
> version of ruby, simply by copy pasting it ? Particularly interested in
> the version I have listed as not working.

Sorry, I can't help you with that, because I can't get the CTR mode 
working.



> edit: also in my full program I set @sha256 in initialize and then reset
> it through a lot of methods, but in this case a local variable would
> certainly be best

Well, a local variable is not only "better" in this case. It's the only 
right way to do this. Using an instance variable doesn't make any sense, 
because you don't want the SHA256 object to be a property of the object.

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