caesarcipher 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cipher.rb +47 -0
  3. data/lib/cli.rb +30 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 233401742a79905b726290737218385bd0c5f0e3
4
+ data.tar.gz: dabb89d30ef5fb46383df069c12c38a8e883d0e8
5
+ SHA512:
6
+ metadata.gz: 9a7fa98512287aa7f040d7366fa0f98e9d03381fda14372c8c3352d5f09cbc369de74ca8c98f4efd6e6a426c50d6123cd57461ef96e7a7ac4aa032eb4f833d89
7
+ data.tar.gz: af779c8579e27ed0b64441ee1c371c11c749a4403326b3ecb84b23f82ba53a372bedc345ab806be437822a0f679f2bb9c8254286cbaa1be185aa767699d6e7f0
data/lib/cipher.rb ADDED
@@ -0,0 +1,47 @@
1
+ class Cipher
2
+ attr_reader :shift_amount, :plaintext
3
+
4
+ def initialize(shift_amount, plaintext)
5
+ @shift_amount = shift_amount
6
+ @plaintext = plaintext
7
+ end
8
+
9
+ def alphabet
10
+ ["A", "B", "C", "D",
11
+ "E", "F", "G", "H",
12
+ "I", "J", "K", "L",
13
+ "M", "N", "O", "P",
14
+ "Q", "R", "S", "T",
15
+ "U", "V", "W", "X",
16
+ "Y", "Z"]
17
+ end
18
+
19
+ def ciphered_alphabet
20
+ append_to_end = alphabet[0..@shift_amount - 1]
21
+ ciphered = alphabet.drop(@shift_amount)
22
+ append_to_end.each do |letter|
23
+ ciphered << letter
24
+ end
25
+ ciphered
26
+ end
27
+
28
+ def alpha_to_cipher
29
+ Hash[alphabet.zip ciphered_alphabet]
30
+ end
31
+
32
+ def encrypt
33
+ split_text = @plaintext.upcase.split("")
34
+ encrypted = ""
35
+ split_text.each do |letter|
36
+ if letter == " "
37
+ encrypted += letter
38
+ elsif !alphabet.include?(letter)
39
+ encrypted += ""
40
+ else
41
+ encrypted_letter = alpha_to_cipher[letter]
42
+ encrypted += encrypted_letter
43
+ end
44
+ end
45
+ encrypted.downcase
46
+ end
47
+ end
data/lib/cli.rb ADDED
@@ -0,0 +1,30 @@
1
+ require './lib/cipher'
2
+
3
+ class Cli
4
+ def initialize
5
+ shift_amount = get_shift_amount
6
+ plaintext = get_plain_text
7
+ cipher = create_cipher(shift_amount, plaintext)
8
+ display_encrypted_text(cipher)
9
+ end
10
+
11
+ def get_shift_amount
12
+ puts "What amount do you want to shift the cipher by? (0-25)"
13
+ gets.chomp.to_i
14
+ end
15
+
16
+ def get_plain_text
17
+ puts "What message do you want to encyrpt?"
18
+ gets.chomp
19
+ end
20
+
21
+ def create_cipher(shift_amount, plaintext)
22
+ Cipher.new(shift_amount, plaintext)
23
+ end
24
+
25
+ def display_encrypted_text(cipher)
26
+ puts cipher.encrypt
27
+ end
28
+ end
29
+
30
+ Cli.new
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caesarcipher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Meagan Waller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: set a shift and encrypt your text like caesar did
14
+ email: meaganewaller@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/cipher.rb
20
+ - lib/cli.rb
21
+ homepage: http://rubygems.org/gems/caesarcipher
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: encrypt text like caesar
45
+ test_files: []