dukpt 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bca5288bcff81b55d59ae8421925e7c99e6b30f
4
- data.tar.gz: 36d53c531ed1b0d25aa4252e3c601a9f15660cae
3
+ metadata.gz: 9de3896da9a40258097ea4f24f88517cd6c90d4a
4
+ data.tar.gz: 42080b60905536315e18bce9acf40cb497f47246
5
5
  SHA512:
6
- metadata.gz: 366979966978f13c5866ac6d987d92bf267c4e82fd795bf19876a40c85c654e1118d68ff600b709ac4721b0cdb64f425580fbfa6f0d84b2d88a3a9fb8af30e0d
7
- data.tar.gz: a5b23896a45fde35f3efcca58572552d8af120acdb618a73f428780595dbc40e761d404357c5394daeb2e9f29c2ebe162b0ed2d7b3e44f4be62dd61cc7bf7fe5
6
+ metadata.gz: 3151da02540b37529b1e74cb0f4ae386273585d996f8c10a1df353807cfa7046e87a020b02470d46783c6ff449a003a0cdc4628ddb5b66828b7785255332afd6
7
+ data.tar.gz: 2fd23eb0c02ce532eb08e23a3251c9c08fcb39d2b87d265ee7e553d1ba70ea9d3c5cf83f6a21a5030e626c79793655c39c4c507b7a01cdf559bf49e777dd2468
@@ -20,6 +20,21 @@ module DUKPT
20
20
  decrypt(cryptogram, ksn)
21
21
  end
22
22
 
23
+ def decrypt_pin(cryptogram, ksn, pan)
24
+ pan &&= pan.downcase.chomp('f')
25
+ decrypted_block = decrypt_pin_block(cryptogram, ksn).unpack("H*").first
26
+ block_format = decrypted_block[0]
27
+ if block_format == "0"
28
+ coded_pan = "0000"+pan[-13..-2]
29
+ coded_pin = (decrypted_block.to_i(16) ^ coded_pan.to_i(16)).to_s(16).rjust(16, '0')
30
+ pin_count = coded_pin[1].to_i
31
+ coded_pin[2,pin_count]
32
+ elsif block_format == "1"
33
+ pin_count = decrypted_block[1]
34
+ coded_pin[2,pin_count]
35
+ end
36
+ end
37
+
23
38
  def decrypt_data_block(cryptogram, ksn)
24
39
  ipek = derive_IPEK(bdk, ksn)
25
40
  dek = derive_DEK(ipek, ksn)
@@ -1,3 +1,3 @@
1
1
  module DUKPT
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -12,10 +12,9 @@ class DUKPT::DecrypterTest < Test::Unit::TestCase
12
12
 
13
13
  decrypter = DUKPT::Decrypter.new(bdk, "cbc")
14
14
  assert_equal plaintext, decrypter.decrypt(ciphertext, ksn)
15
- assert_equal plaintext, decrypter.decrypt_pin_block(ciphertext, ksn)
16
15
  end
17
16
 
18
- def test_decrypt_data_block
17
+ def test_decrypt_data_block
19
18
  bdk = "0123456789ABCDEFFEDCBA9876543210"
20
19
  ksn = "FFFF01040DA058E00001"
21
20
  ciphertext = "85A8A7F9390FD19EABC40B5D624190287D729923D9EDAFE9F24773388A9A1BEF"
@@ -24,5 +23,27 @@ class DUKPT::DecrypterTest < Test::Unit::TestCase
24
23
  decrypter = DUKPT::Decrypter.new(bdk, "cbc")
25
24
  assert_equal plaintext, decrypter.decrypt_data_block(ciphertext, ksn)
26
25
  end
26
+
27
+ def test_decrypt_pin
28
+ bdk = "0123456789ABCDEFFEDCBA9876543210"
29
+ ksn = "F8765432108D12400014"
30
+ ciphertext = "129C4FC2537BB63E"
31
+ pan = "5413330089601109"
32
+ plaintext_pin = "4315"
33
+
34
+ decrypter = DUKPT::Decrypter.new(bdk)
35
+ assert_equal plaintext_pin, decrypter.decrypt_pin(ciphertext, ksn, pan)
36
+ end
27
37
 
38
+ def test_decrypt_pin_with_padded_pan
39
+ bdk = "0123456789ABCDEFFEDCBA9876543210"
40
+ ksn = "F8765432108D12400011"
41
+ ciphertext = "8C3169A2ABC1632F"
42
+ pan = "6799998900000060919F"
43
+ plaintext_pin = "4315"
44
+
45
+ decrypter = DUKPT::Decrypter.new(bdk)
46
+ assert_equal plaintext_pin, decrypter.decrypt_pin(ciphertext, ksn, pan)
47
+ end
48
+
28
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dukpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Seal
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-05 00:00:00.000000000 Z
12
+ date: 2015-07-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Implements a Derived Unique Key Per Transaction (DUKPT) decrypter
15
15
  email:
@@ -19,7 +19,7 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".gitignore"
22
+ - .gitignore
23
23
  - Gemfile
24
24
  - LICENSE
25
25
  - README.md
@@ -40,17 +40,17 @@ require_paths:
40
40
  - lib
41
41
  required_ruby_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ">="
43
+ - - '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ">="
48
+ - - '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.2.2
53
+ rubygems_version: 2.0.14
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Implements a Derived Unique Key Per Transaction (DUKPT) decrypter