RC5 algorithm in Ruby
In cryptography, RC5 is a symmetric-key block cipher notable for its simplicity. RC5 has a variable block size (32, 64 or 128 bits). You can change it with W constant.
The following variable names are used:
- b - The length of the key in bytes
- key - The key, considered as an array of bytes (using 0-based indexing)
- W - The length of a word in bits. Typical values of this in RC5 are 16, 32, and 64. Note that a "block" is two words long
- R - The number of rounds to use when encrypting data
- S - The expanded list of words derived from the key, of length 2(r+1), with each element being a word
- L - A convenience to encapsulate K as an array of word-sized values rather than byte-sized
key = 'some_string_for_key'
ob = RC5.new(key)
text = 'some_text_to_be_encrypted'
enc = ob.encypt_text(text)
puts enc #==> l�@������K����^ڨ���"����
dec = ob.decrypt_text(enc)
puts dec #==> some_text_to_be_encrypted
Algorithm was taken from github project and rebuilt into Ruby.