titanous
titanous

Reputation: 3678

Ruby Integer to Binary string

I need to encrypt a integer, but all the crypto libraries only support strings.

What is the proper method to convert a integer to a binary string in Ruby? (not '10111', I think that it's ASCII values)

EDIT: I wasn't thinking about Rijndael as stream encryption.

Upvotes: 0

Views: 1699

Answers (1)

dirkgently
dirkgently

Reputation: 111130

Stream encryption algorithms work on streams -- a sequence of characters. It is upto you to treat is as an integer or a newline.

Rijndael (a block cipher) will happily accept a non-128 bit string (stream, if you will) and padd the end with 0s. Check out the documentation and give it a shot.

Upvotes: 1

Related Questions