Module: KBEncryptionMixin
- Included in:
- KBEngine, KBIndex, KBRecnoIndex
- Defined in:
- lib/kirbybase.rb
Overview
KBEncryptionMixin
Constant Summary collapse
- EN_STR =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + \ '0123456789.+-,$:|&;_ '
- EN_STR_LEN =
EN_STR.length
- EN_KEY1 =
*** DO NOT CHANGE ***
")2VER8GE\"87-E\n"- EN_KEY =
- EN_KEY_LEN =
EN_KEY.length
Instance Method Summary collapse
-
#encrypt_str(s) ⇒ Object
———————————————————————– encrypt_str ———————————————————————– ++ Returns an encrypted string, using the Vignere Cipher.
-
#unencrypt_str(s) ⇒ Object
———————————————————————– unencrypt_str ———————————————————————– ++ Returns an unencrypted string, using the Vignere Cipher.
Instance Method Details
#encrypt_str(s) ⇒ Object
encrypt_str
++ Returns an encrypted string, using the Vignere Cipher.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/kirbybase.rb', line 318 def encrypt_str(s) new_str = '' i_key = -1 s.each_byte do |c| if i_key < EN_KEY_LEN - 1 i_key += 1 else i_key = 0 end if EN_STR.index(c.chr).nil? new_str << c.chr next end i_from_str = EN_STR.index(EN_KEY[i_key]) + EN_STR.index(c.chr) i_from_str = i_from_str - EN_STR_LEN if i_from_str >= EN_STR_LEN new_str << EN_STR[i_from_str] end return new_str end |
#unencrypt_str(s) ⇒ Object
unencrypt_str
++ Returns an unencrypted string, using the Vignere Cipher.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/kirbybase.rb', line 346 def unencrypt_str(s) new_str = '' i_key = -1 s.each_byte do |c| if i_key < EN_KEY_LEN - 1 i_key += 1 else i_key = 0 end if EN_STR.index(c.chr).nil? new_str << c.chr next end i_from_str = EN_STR.index(c.chr) - EN_STR.index(EN_KEY[i_key]) i_from_str = i_from_str + EN_STR_LEN if i_from_str < 0 new_str << EN_STR[i_from_str] end return new_str end |