class CipherworldAmitjuly2020::Cipher::LetterLetter
Public Class Methods
new(char_set: )
click to toggle source
# File lib/cipherworld_amitjuly2020.rb, line 68 def initialize(char_set: ) @char_set = char_set end
Public Instance Methods
decrypt(encryptedtext)
click to toggle source
# File lib/cipherworld_amitjuly2020.rb, line 82 def decrypt(encryptedtext) #string.chars.each{|x| decrypt_errors} begin ciphered = string.chars.map{|x| dictionary.fetch(x)}.join rescue KeyError => e puts "Unsuitable text for cipher: #{e}" end decrypted = encryptedtext.chars.map{|x| dictionary.key(x)}.join end
encrypt(string)
click to toggle source
# File lib/cipherworld_amitjuly2020.rb, line 72 def encrypt(string) # fetching letter and encrypting it #string.chars.each{|x| char_errors} begin ciphered = string.chars.map{|x| dictionary.fetch(x)}.join rescue KeyError => e puts "Unsuitable text for cipher: #{e}" end end
Private Instance Methods
dictionary()
click to toggle source
# File lib/cipherworld_amitjuly2020.rb, line 94 def dictionary character_set = {} text_file.each{|x| character_set[x[0]] = x[3]} character_set end