module AllegedRc4
Public Class Methods
to_alleged(message, key)
click to toggle source
@param [String] message, key @param [String] key @return [String]
# File lib/allegedrc4.rb, line 7 def self.to_alleged(message, key) index1 = 0 index2 = 0 result = '' state = [] (0..255).each do |i| state.push i end (0..255).each do |i| index2 = (key[index1].ord + state[i] + index2) % 256 state[i], state[index2] = swap_val(state[i], state[index2]) index1 = (index1 + 1) % key.length end x = 0 y = 0 (0..message.length - 1).each do |i| x = (x + 1) % 256 y = (state[x] + y) % 256 state[x], state[y] = swap_val(state[x], state[y]) message_str = message[i].ord ^ state[(state[x] + state[y]) % 256] result += '-' + fill_zero(message_str.to_s(16)) end result[1, result.length - 1].upcase end
Private Class Methods
fill_zero(val)
click to toggle source
@param [String] val @return [String]
# File lib/allegedrc4.rb, line 39 def self.fill_zero(val) return "0#{val}" if val.length == 1 val end
swap_val(value_for, value_to)
click to toggle source
# File lib/allegedrc4.rb, line 45 def self.swap_val(value_for, value_to) [value_to, value_for] end