cryptograms 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1af4eafc9cb579862e3b56f687fad766b44d4851
4
+ data.tar.gz: ac46573d22243a28083089cdc84333548692fdfc
5
+ SHA512:
6
+ metadata.gz: 9f034a8c1a20742596dfeeca65fc1ce3d000afd688eab0b1a5e6e3e2272ec693d9ec7a6a148bfc5861ddc7f8bd57a381111e34278dce5aba1726584e9b08c859
7
+ data.tar.gz: e56d92e08ac044158e6b9b0da033844733b3c261d28b715ab2c3831be8290a1a0cec261a472c64a518c7c5f205a5a762143621de65f0824268ee2fc672338f2c
data/AUTHORS ADDED
@@ -0,0 +1,16 @@
1
+ cryptograms: generate cryptograms using a pseudo-random letter
2
+ subtitution cypher
3
+ Copyright (C) 2015 Todd A. Jacobs
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "guard-rspec", require: false
7
+ gem "pry"
8
+ end
data/bin/cryptogram ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/cryptograms'
4
+
5
+ notices = [
6
+ "Cryptograms v#{Cryptograms::VERSION}",
7
+ 'Copyright © 2015 Todd A. Jacobs',
8
+ 'This program is licensed under GPLv3 or later.',
9
+ ]
10
+ warn "#{notices.join ?\n}\n\n"
11
+
12
+ puts Cryptogram.new(ARGV.join ' ').cyphertext
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cryptograms/version'
5
+ require 'rake'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'cryptograms'
9
+ spec.version = Cryptograms::VERSION
10
+ spec.authors = ['Todd A. Jacobs']
11
+ spec.email = ['codegnome@address-is.invalid']
12
+
13
+ spec.summary = 'Create cryptogram puzzles.'
14
+ spec.description = 'Generate cryptograms using a pseudo-random ' +
15
+ 'letter subtitution cypher.'
16
+ spec.homepage = 'https://github.com/CodeGnome/cryptograms'
17
+ spec.license = 'GPLv3'
18
+ spec.files = FileList[
19
+ 'AUTHORS',
20
+ 'Gemfile',
21
+ 'bin/cryptogram',
22
+ 'cryptograms.gemspec',
23
+ 'lib/**/*',
24
+ ]
25
+ spec.bindir = 'bin'
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.9'
30
+ spec.add_development_dependency 'rake', '~> 10.4'
31
+ spec.add_development_dependency 'rspec', '~> 3.2'
32
+ end
@@ -0,0 +1,30 @@
1
+ class Cryptogram
2
+ attr_reader :cyphertext, :plaintext, :key
3
+ ALPHABET = (?A..?Z).to_a.map(&:freeze).freeze
4
+
5
+ def initialize plaintext
6
+ @plaintext = plaintext.upcase
7
+ @cyphertext = @plaintext.tr ALPHABET.join, cypher.join
8
+ end
9
+
10
+ # Randomize until no cyphertext replacement is the same as the original
11
+ # letter.
12
+ def cypher
13
+ loop do
14
+ (@key ||= ALPHABET.dup).shuffle!
15
+ redo if @key.zip(ALPHABET).any? { |k, v| k == v }
16
+ return @key
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def rosetta_stone
23
+ ALPHABET.zip @key
24
+ end
25
+ end
26
+
27
+ if __FILE__ == $0
28
+ c = Cryptogram.new ARGV[0]
29
+ puts c.cyphertext
30
+ end
@@ -0,0 +1,3 @@
1
+ module Cryptograms
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cryptograms/cryptogram'
5
+ require 'cryptograms/version'
6
+
7
+ if __FILE__ == $PROGRAM_NAME
8
+ c = Cryptogram.new ARGV[0]
9
+ puts c.cyphertext
10
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptograms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Todd A. Jacobs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Generate cryptograms using a pseudo-random letter subtitution cypher.
56
+ email:
57
+ - codegnome@address-is.invalid
58
+ executables:
59
+ - cryptogram
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - AUTHORS
64
+ - Gemfile
65
+ - bin/cryptogram
66
+ - cryptograms.gemspec
67
+ - lib/cryptograms.rb
68
+ - lib/cryptograms/cryptogram.rb
69
+ - lib/cryptograms/version.rb
70
+ homepage: https://github.com/CodeGnome/cryptograms
71
+ licenses:
72
+ - GPLv3
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Create cryptogram puzzles.
94
+ test_files: []