crypt19-rb 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 642bbab526866578e06c0e06654c51fc88be89eb
4
- data.tar.gz: 67efa313253fc737a330bda5c6d7ec55623cec2a
3
+ metadata.gz: 4a9f3b81613ed54c16adf3a776b71a2eea6f0aac
4
+ data.tar.gz: cb6d1a9558c0e5e92852e226348a59d97b8af978
5
5
  SHA512:
6
- metadata.gz: 838a590fdf6b85b58d323dfcd703bff6b088993b45245dd337195335e2076d836e634f1e7cd33453e22d50ffcdf78b303ee5dd610aab60c7c448d0d5d9c5974b
7
- data.tar.gz: 54063059f98b42d761ff5082c55288008c76300cf35fe0504b135c45c1042ba02832dab46b6c0c67157274399cb05b8e7d3714b5293c6f7e5e5419ae099531a3
6
+ metadata.gz: 28e0676f55f90ee1f2290ef59b9b624f565340a8970f2f9921feea0168d6e337ab228280f77e84c846d85c5bcfc7fcf262a63dc7bf5fc919017bd33b1f1ed3be
7
+ data.tar.gz: d822bd479b2a300b53382b48427d6a8105462168a1397c1fd9198deb4663f9912c82989eeffa82c28661096b06daee76c9a95ddc52a3638ef18049f8e5c81c94
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crypt19-rb (1.2.1)
4
+ crypt19-rb (1.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  module Crypt
2
3
  module BlowfishTables
3
4
 
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  # Blowfish algorithm by Bruce Schneider
2
3
  # Ported from the reference C code
3
4
 
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  class String
2
3
  if RUBY_VERSION =~ /1\.8/
3
4
  def getbyte(index)
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  require 'stringio'
2
3
  require 'crypt/stringxor'
3
4
 
@@ -1,138 +1,139 @@
1
- # adapted from C++ code written by Wei Dai
2
- # of the Crypto++ project http://www.eskimo.com/~weidai/cryptlib.html
3
-
4
- require 'crypt/cbc'
5
-
6
- module Crypt
7
- class Gost
8
-
9
- include CBC
10
-
11
- ULONG = 0x100000000
12
-
13
- def block_size
14
- return(8)
15
- end
16
-
17
-
18
- def initialize(user_key)
19
-
20
- # These are the S-boxes given in Applied Cryptography 2nd Ed., p. 333
21
- @sBox = [
22
- [4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3],
23
- [14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9],
24
- [5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11],
25
- [7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3],
26
- [6, 12, 7, 1, 5, 15, 13, 8, 4, 10, 9, 14, 0, 3, 11, 2],
27
- [4, 11, 10, 0, 7, 2, 1, 13, 3, 6, 8, 5, 9, 12, 15, 14],
28
- [13, 11, 4, 1, 3, 15, 5, 9, 0, 10, 14, 7, 6, 8, 2, 12],
29
- [1, 15, 13, 0, 5, 7, 10, 4, 9, 2, 3, 14, 6, 11, 8, 12]
30
- ]
31
-
32
- # These are the S-boxes given in the GOST source code listing in Applied
33
- # Cryptography 2nd Ed., p. 644. They appear to be from the DES S-boxes
34
- # [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 ],
35
- # [ 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 ],
36
- # [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 ],
37
- # [ 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 ],
38
- # [ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 ],
39
- # [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 ],
40
- # [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 ],
41
- # [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 ]
42
-
43
- # precalculate the S table
44
- @s_table = precalculate_s_table()
45
-
46
- # derive the 32-byte key from the user-supplied key
47
- user_key_length = user_key.length
48
- @key = user_key[0..31].unpack('C'*32)
49
- if (user_key_length < 32)
50
- user_key_length.upto(31) { @key << 0 }
51
- end
52
- end
53
-
54
-
55
- def precalculate_s_table()
56
- s_table = [[], [], [], []]
57
- 0.upto(3) { |i|
58
- 0.upto(255) { |j|
59
- t = @sBox[2*i][j % 16] | (@sBox[2*i+1][j/16] << 4)
60
- u = (8*i + 11) % 32
61
- v = (t << u) | (t >> (32-u))
62
- s_table[i][j] = (v % ULONG)
63
- }
64
- }
65
- return(s_table)
66
- end
67
-
68
-
69
- def f(long_word)
70
- long_word = long_word % ULONG
71
- a, b, c, d = [long_word].pack('L').unpack('CCCC')
72
- return(@s_table[3][d] ^ @s_table[2][c] ^ @s_table[1][b] ^ @s_table[0][a])
73
- end
74
-
75
-
76
- def encrypt_pair(xl, xr)
77
- 3.times {
78
- xr ^= f(xl+@key[0])
79
- xl ^= f(xr+@key[1])
80
- xr ^= f(xl+@key[2])
81
- xl ^= f(xr+@key[3])
82
- xr ^= f(xl+@key[4])
83
- xl ^= f(xr+@key[5])
84
- xr ^= f(xl+@key[6])
85
- xl ^= f(xr+@key[7])
86
- }
87
- xr ^= f(xl+@key[7])
88
- xl ^= f(xr+@key[6])
89
- xr ^= f(xl+@key[5])
90
- xl ^= f(xr+@key[4])
91
- xr ^= f(xl+@key[3])
92
- xl ^= f(xr+@key[2])
93
- xr ^= f(xl+@key[1])
94
- xl ^= f(xr+@key[0])
95
- return([xr, xl])
96
- end
97
-
98
-
99
- def decrypt_pair(xl, xr)
100
- xr ^= f(xl+@key[0])
101
- xl ^= f(xr+@key[1])
102
- xr ^= f(xl+@key[2])
103
- xl ^= f(xr+@key[3])
104
- xr ^= f(xl+@key[4])
105
- xl ^= f(xr+@key[5])
106
- xr ^= f(xl+@key[6])
107
- xl ^= f(xr+@key[7])
108
- 3.times {
109
- xr ^= f(xl+@key[7])
110
- xl ^= f(xr+@key[6])
111
- xr ^= f(xl+@key[5])
112
- xl ^= f(xr+@key[4])
113
- xr ^= f(xl+@key[3])
114
- xl ^= f(xr+@key[2])
115
- xr ^= f(xl+@key[1])
116
- xl ^= f(xr+@key[0])
117
- }
118
- return([xr, xl])
119
- end
120
-
121
-
122
- def encrypt_block(block)
123
- xl, xr = block.unpack('NN')
124
- xl, xr = encrypt_pair(xl, xr)
125
- encrypted = [xl, xr].pack('NN')
126
- return(encrypted)
127
- end
128
-
129
-
130
- def decrypt_block(block)
131
- xl, xr = block.unpack('NN')
132
- xl, xr = decrypt_pair(xl, xr)
133
- decrypted = [xl, xr].pack('NN')
134
- return(decrypted)
135
- end
136
-
137
- end
1
+ # coding: ASCII
2
+ # adapted from C++ code written by Wei Dai
3
+ # of the Crypto++ project http://www.eskimo.com/~weidai/cryptlib.html
4
+
5
+ require 'crypt/cbc'
6
+
7
+ module Crypt
8
+ class Gost
9
+
10
+ include CBC
11
+
12
+ ULONG = 0x100000000
13
+
14
+ def block_size
15
+ return(8)
16
+ end
17
+
18
+
19
+ def initialize(user_key)
20
+
21
+ # These are the S-boxes given in Applied Cryptography 2nd Ed., p. 333
22
+ @sBox = [
23
+ [4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3],
24
+ [14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9],
25
+ [5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11],
26
+ [7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3],
27
+ [6, 12, 7, 1, 5, 15, 13, 8, 4, 10, 9, 14, 0, 3, 11, 2],
28
+ [4, 11, 10, 0, 7, 2, 1, 13, 3, 6, 8, 5, 9, 12, 15, 14],
29
+ [13, 11, 4, 1, 3, 15, 5, 9, 0, 10, 14, 7, 6, 8, 2, 12],
30
+ [1, 15, 13, 0, 5, 7, 10, 4, 9, 2, 3, 14, 6, 11, 8, 12]
31
+ ]
32
+
33
+ # These are the S-boxes given in the GOST source code listing in Applied
34
+ # Cryptography 2nd Ed., p. 644. They appear to be from the DES S-boxes
35
+ # [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 ],
36
+ # [ 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 ],
37
+ # [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 ],
38
+ # [ 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 ],
39
+ # [ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 ],
40
+ # [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 ],
41
+ # [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 ],
42
+ # [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 ]
43
+
44
+ # precalculate the S table
45
+ @s_table = precalculate_s_table()
46
+
47
+ # derive the 32-byte key from the user-supplied key
48
+ user_key_length = user_key.length
49
+ @key = user_key[0..31].unpack('C'*32)
50
+ if (user_key_length < 32)
51
+ user_key_length.upto(31) { @key << 0 }
52
+ end
53
+ end
54
+
55
+
56
+ def precalculate_s_table()
57
+ s_table = [[], [], [], []]
58
+ 0.upto(3) { |i|
59
+ 0.upto(255) { |j|
60
+ t = @sBox[2*i][j % 16] | (@sBox[2*i+1][j/16] << 4)
61
+ u = (8*i + 11) % 32
62
+ v = (t << u) | (t >> (32-u))
63
+ s_table[i][j] = (v % ULONG)
64
+ }
65
+ }
66
+ return(s_table)
67
+ end
68
+
69
+
70
+ def f(long_word)
71
+ long_word = long_word % ULONG
72
+ a, b, c, d = [long_word].pack('L').unpack('CCCC')
73
+ return(@s_table[3][d] ^ @s_table[2][c] ^ @s_table[1][b] ^ @s_table[0][a])
74
+ end
75
+
76
+
77
+ def encrypt_pair(xl, xr)
78
+ 3.times {
79
+ xr ^= f(xl+@key[0])
80
+ xl ^= f(xr+@key[1])
81
+ xr ^= f(xl+@key[2])
82
+ xl ^= f(xr+@key[3])
83
+ xr ^= f(xl+@key[4])
84
+ xl ^= f(xr+@key[5])
85
+ xr ^= f(xl+@key[6])
86
+ xl ^= f(xr+@key[7])
87
+ }
88
+ xr ^= f(xl+@key[7])
89
+ xl ^= f(xr+@key[6])
90
+ xr ^= f(xl+@key[5])
91
+ xl ^= f(xr+@key[4])
92
+ xr ^= f(xl+@key[3])
93
+ xl ^= f(xr+@key[2])
94
+ xr ^= f(xl+@key[1])
95
+ xl ^= f(xr+@key[0])
96
+ return([xr, xl])
97
+ end
98
+
99
+
100
+ def decrypt_pair(xl, xr)
101
+ xr ^= f(xl+@key[0])
102
+ xl ^= f(xr+@key[1])
103
+ xr ^= f(xl+@key[2])
104
+ xl ^= f(xr+@key[3])
105
+ xr ^= f(xl+@key[4])
106
+ xl ^= f(xr+@key[5])
107
+ xr ^= f(xl+@key[6])
108
+ xl ^= f(xr+@key[7])
109
+ 3.times {
110
+ xr ^= f(xl+@key[7])
111
+ xl ^= f(xr+@key[6])
112
+ xr ^= f(xl+@key[5])
113
+ xl ^= f(xr+@key[4])
114
+ xr ^= f(xl+@key[3])
115
+ xl ^= f(xr+@key[2])
116
+ xr ^= f(xl+@key[1])
117
+ xl ^= f(xr+@key[0])
118
+ }
119
+ return([xr, xl])
120
+ end
121
+
122
+
123
+ def encrypt_block(block)
124
+ xl, xr = block.unpack('NN')
125
+ xl, xr = encrypt_pair(xl, xr)
126
+ encrypted = [xl, xr].pack('NN')
127
+ return(encrypted)
128
+ end
129
+
130
+
131
+ def decrypt_block(block)
132
+ xl, xr = block.unpack('NN')
133
+ xl, xr = decrypt_pair(xl, xr)
134
+ decrypted = [xl, xr].pack('NN')
135
+ return(decrypted)
136
+ end
137
+
138
+ end
138
139
  end
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  # IDEA (International Data Encryption Algorithm) by
2
3
  # Xuejia Lai and James Massey (1992). Refer to license info at the end of this file.
3
4
 
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  # add_noise - take a message and intersperse noise to make a new noisy message of given byte-length
2
3
  # remove_noise - take a noisy message and extract the message
3
4
 
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  # RC6 symmetric key block cipher
2
3
  # RC6 is a patented encryption algorithm (U.S. Patent 5,724,428 and U.S. Patent 5,835,600)
3
4
  # Ported by Alexey Lapitsky <lex.public@gmail.com> (2009)
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  module Crypt
2
3
  module RijndaelTables
3
4
 
@@ -1,3 +1,4 @@
1
+ # coding: ASCII-8BIT
1
2
  # Adapted from the reference C implementation:
2
3
  # rijndael-alg-ref.c v2.2 March 2002
3
4
  # Reference ANSI C code by Paulo Barreto and Vincent Rijmen
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  module Crypt
2
3
  module StringXor
3
4
 
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  module Crypt
2
- VERSION = "1.2.1"
3
+ VERSION = "1.2.2"
3
4
  end
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  require 'test/unit'
2
3
  require 'crypt/blowfish'
3
4
  require 'crypt/cbc'
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  require 'test/unit'
2
3
  require 'crypt/gost'
3
4
  require 'fileutils'
@@ -37,7 +38,7 @@ class TestGost < Test::Unit::TestCase
37
38
  decrypted_block = gost.decrypt_block(encrypted_block)
38
39
  assert_equal(block, decrypted_block)
39
40
  end
40
-
41
+
41
42
  def test_string
42
43
  length = 25 + rand(12)
43
44
  userkey = ""
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  require 'test/unit'
2
3
  require 'crypt/idea'
3
4
  require 'fileutils'
@@ -36,7 +37,7 @@ class TestIdea < Test::Unit::TestCase
36
37
  decrypted_block = idea_de.decrypt_block(encrypted_block)
37
38
  assert_equal(block, decrypted_block)
38
39
  end
39
-
40
+
40
41
  def test_string
41
42
  length = 25 + rand(12)
42
43
  userkey = ""
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  require 'test/unit'
2
3
  require 'crypt/rc6'
3
4
  require 'fileutils'
@@ -1,3 +1,4 @@
1
+ # coding: ASCII
1
2
  require 'test/unit'
2
3
  require 'crypt/rijndael'
3
4
  require 'fileutils'
@@ -32,7 +33,7 @@ class TestRijndael < Test::Unit::TestCase
32
33
  encrypted_block = rijndael.encrypt_block(block)
33
34
  }
34
35
  end
35
-
36
+
36
37
  def test_string
37
38
  rijndael = Crypt::Rijndael.new("Who is this John Galt guy, anyway?")
38
39
  string = "This is a string which is not a multiple of 8 characters long"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypt19-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rudenberg
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-26 00:00:00.000000000 Z
13
+ date: 2013-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.0.0
82
+ rubygems_version: 2.0.3
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Crypt is a pure-ruby implementation of a number of popular encryption algorithms.