Class: Origami::Encryption::ARC4
- Inherits:
-
Object
- Object
- Origami::Encryption::ARC4
- Defined in:
- lib/origami/encryption.rb
Overview
Pure Ruby implementation of the aRC4 symmetric algorithm
Class Method Summary collapse
-
.decrypt(key, data) ⇒ Object
Decrypts data using the given key.
-
.encrypt(key, data) ⇒ Object
Encrypts data using the given key.
Instance Method Summary collapse
-
#cipher(data) ⇒ Object
(also: #encrypt, #decrypt)
Encrypt/decrypt data with the aRC4 encryption algorithm.
-
#initialize(key) ⇒ ARC4
constructor
Creates and initialises a new aRC4 generator using given key.
Constructor Details
Class Method Details
Instance Method Details
#cipher(data) ⇒ Object Also known as: encrypt, decrypt
Encrypt/decrypt data with the aRC4 encryption algorithm
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/origami/encryption.rb', line 559 def cipher(data) return "" if data.empty? if Origami::OPTIONS[:use_openssl] rc4 = OpenSSL::Cipher::RC4.new.encrypt rc4.key_len = @key.length rc4.key = @key output = rc4.update(data) << rc4.final else output = "" i, j = 0, 0 data.each_byte do |byte| i = i.succ & 0xFF j = (j + @state[i]) & 0xFF @state[i], @state[j] = @state[j], @state[i] output << (@state[@state[i] + @state[j] & 0xFF] ^ byte).chr end end output end |