Class: Fog

Inherits:
String show all
Defined in:
lib/external/fog.rb

Constant Summary collapse

VERSION =
'1.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Crypt::StringXor

#^

Constructor Details

#initialize(string, degree = 13) ⇒ Fog

Returns an encrypted string based on the degree that you pass. The default degree is 13. The degree is more or less a salt value.



7
8
9
10
11
# File 'lib/external/fog.rb', line 7

def initialize(string, degree=13)
   @degree = degree.to_i
   str = encrypt(string, degree)
   super(str)
end

Class Method Details

.decrypt(string, degree = 13) ⇒ Object

Decrypts an arbitrary string using degree. You must know the degree with which the string was originally encrypted in order for this method to work properly.



30
31
32
# File 'lib/external/fog.rb', line 30

def self.decrypt(string, degree=13)
   string.unpack('C*').map{ |e| e -= degree }.pack('C*')
end

Instance Method Details

#decryptObject

Decrypts the string using the degree passed to the constructor.



15
16
17
# File 'lib/external/fog.rb', line 15

def decrypt
   unpack('C*').map{ |e| e -= @degree }.pack('C*')
end

#to_sObject

The to_s method is identical to inspect, in order to prevent the literal quotation marks from potentially messing up things.



22
23
24
# File 'lib/external/fog.rb', line 22

def to_s
   inspect
end