affine 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,37 @@
1
1
  = affine
2
2
 
3
- Simple affine cipher
3
+ An affine cipher is a monoalphabetic substitution cipher, that uses
4
+ math to generate the substitution alphabet based on three paramaters:
5
+
6
+ [modulus] specifies how many different plaintexts and ciphertexts
7
+ are available.
8
+ [a_key] multiplied against the plaintext. <b>Must be coprime with
9
+ the modulus.</b>
10
+ [b_key] added to the multiplied plaintext. No restrictions, but
11
+ it's modulus math, so making it larger than +modulus+ is
12
+ useless.
13
+
14
+ These parameters are passed in order to the Cipher constructor:
4
15
 
5
16
  a = Affine::Cipher.new(2176782371, 65182241782, 123235151)
6
17
  r = rand(123235150) # (should be smaller then the modulus)
7
- r == a.decipher(a.encipher r)
18
+ ciphertext = a.encipher r
19
+ # ciphertext = ((r * 65182241782) + 123235151) % 2176782371
20
+ r == a.decipher(ciphertext)
21
+
22
+ == Giant security caveat
23
+
24
+ Don't use this cipher for security related tasks. I'm using it
25
+ to make primary keys alphanumeric and less-predictable:
26
+ http://github.com/bkerley/have-code/
27
+
28
+ == How to crack it
29
+
30
+ Know two plaintexts and their ciphertexts, put into linear system, solve.
31
+
32
+ Know the relation between two plaintexts, predict future ciphertexts.
33
+
34
+ Know lots of ciphertexts, guess it's English, solve like a cryptogram.
8
35
 
9
36
  == Copyright
10
37
 
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :minor: 2
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{affine}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryce Kerley"]
9
- s.date = %q{2009-05-18}
9
+ s.date = %q{2009-06-10}
10
10
  s.email = %q{bkerley@brycekerley.net}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -28,12 +28,20 @@ module Affine
28
28
  end
29
29
 
30
30
  # Encrypt one +plaintext+ into a +ciphertext+.
31
+ #
32
+ # == Argument
33
+ # [+plaintext+] a single positive integer between 0 and the +modulus+
34
+ # for the cipher
31
35
  def encipher(plaintext)
32
36
  raise RangeError.new(plaintext, @modulus) if plaintext > @modulus
33
37
  ((@a_key * plaintext) + @b_key) % @modulus
34
38
  end
35
39
 
36
40
  # Decrypt one +ciphertext+ into a +plaintext+.
41
+ #
42
+ # == Argument
43
+ # [+ciphertext+] a single positive integer between 0 and the +modulus+
44
+ # for the cipher
37
45
  def decipher(ciphertext)
38
46
  raise RangeError.new(ciphertext, @modulus) if ciphertext > @modulus
39
47
  (@a_inv * (ciphertext - @b_key)) % @modulus
@@ -13,7 +13,7 @@ module Affine
13
13
  #
14
14
  # Keys and moduli from external sources might raise these.
15
15
  class CoprimeError < AffineError
16
- def initialize(a, b) #:nodoc:
16
+ def initialize(a, b) #:nodoc: :notnew:
17
17
  super("Expected #{a} to be coprime with #{b}")
18
18
  end
19
19
  end
@@ -23,7 +23,7 @@ module Affine
23
23
  # Plaintexts or ciphertexts from external sources might
24
24
  # raise these.
25
25
  class RangeError < AffineError
26
- def initialize(n, mod) #:nodoc:
26
+ def initialize(n, mod) #:nodoc: :notnew:
27
27
  super("Expected input #{n} to be smaller than modulus #{mod}")
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: affine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce Kerley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -04:00
12
+ date: 2009-06-10 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15