present-cipher 0.1.0 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/present/cipher/error.rb +12 -0
- data/lib/present/cipher/version.rb +1 -1
- data/lib/present/cipher.rb +17 -1
- metadata +3 -3
- data/present-cipher.gemspec +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36f722bbd51bc59a36df3f047589f45fc0cabec26320e8101da317292615d992
|
4
|
+
data.tar.gz: 2b6d314798df04c1e8ed76c87c7ec829992e52aa4b51c26b015c2e566a607663
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29819e47113016e1486b164a519d262632384aa049bd8f77c3df2bd480fc3db073df177c4e95fa14640823a1fd2e42f2764dede07bbfbff11d2392ef72e47056
|
7
|
+
data.tar.gz: 025d530a9eb07b8e09b5ecf65dd170b7c0f3312953cdbd58b7ce66c91bf1ae65639ec24523e42f8c731f140f96cb7ec516c88827cea91b1329d52532946c253b
|
data/CHANGELOG.md
CHANGED
data/lib/present/cipher.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "cipher/error"
|
3
4
|
require_relative "cipher/version"
|
4
5
|
|
5
6
|
module Present
|
6
7
|
class Cipher
|
8
|
+
KEY_BYTESIZE = 10
|
9
|
+
KEY_BITSIZE = KEY_BYTESIZE * 8
|
10
|
+
|
11
|
+
BLOCK_BYTESIZE = 8
|
12
|
+
BLOCK_BITSIZE = BLOCK_BYTESIZE * 8
|
13
|
+
|
7
14
|
S_BOX = [
|
8
|
-
0x0C, 0x05, 0x06, 0x0b, 0x09, 0x00, 0x0a, 0x0d, 0x03, 0x0e, 0x0f, 0x08, 0x04, 0x07, 0x01, 0x02
|
15
|
+
0x0C, 0x05, 0x06, 0x0b, 0x09, 0x00, 0x0a, 0x0d, 0x03, 0x0e, 0x0f, 0x08, 0x04, 0x07, 0x01, 0x02,
|
9
16
|
]
|
10
17
|
|
11
18
|
INVERSE_S_BOX = 0.upto(S_BOX.length - 1).map { |n| S_BOX.index(n) }
|
@@ -20,10 +27,16 @@ module Present
|
|
20
27
|
INVERSE_P_BOX = 0.upto(P_BOX.length - 1).map { |n| P_BOX.index(n) }
|
21
28
|
|
22
29
|
def initialize(key)
|
30
|
+
bitsize = key.bytesize * 8
|
31
|
+
raise KeyError, "key length is invalid (expected #{KEY_BITSIZE} bits; got #{bitsize})" if bitsize != KEY_BITSIZE
|
32
|
+
|
23
33
|
@key = key
|
24
34
|
end
|
25
35
|
|
26
36
|
def encrypt(bytes)
|
37
|
+
bitsize = bytes.bytesize * 8
|
38
|
+
raise BlockError, "block length is invalid (expected #{BLOCK_BITSIZE} bits; got #{bitsize})" if bitsize != BLOCK_BITSIZE
|
39
|
+
|
27
40
|
bits = bytes.unpack1("Q>")
|
28
41
|
|
29
42
|
0.upto(30) do |i|
|
@@ -38,6 +51,9 @@ module Present
|
|
38
51
|
end
|
39
52
|
|
40
53
|
def decrypt(bytes)
|
54
|
+
bitsize = bytes.bytesize * 8
|
55
|
+
raise BlockError, "block length is invalid (expected #{BLOCK_BITSIZE} bits; got #{bitsize})" if bitsize != BLOCK_BITSIZE
|
56
|
+
|
41
57
|
bits = bytes.unpack1("Q>")
|
42
58
|
|
43
59
|
31.downto(1) do |i|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: present-cipher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Phan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -25,8 +25,8 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- lib/present/cipher.rb
|
28
|
+
- lib/present/cipher/error.rb
|
28
29
|
- lib/present/cipher/version.rb
|
29
|
-
- present-cipher.gemspec
|
30
30
|
- sig/present/cipher.rbs
|
31
31
|
homepage: https://codeberg.org/htp/present-cipher
|
32
32
|
licenses:
|
data/present-cipher.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/present/cipher/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "present-cipher"
|
7
|
-
spec.version = Present::Cipher::VERSION
|
8
|
-
spec.authors = ["Henry Phan"]
|
9
|
-
spec.email = ["henry@henryphan.com"]
|
10
|
-
|
11
|
-
spec.summary = "A Ruby implementation of the PRESENT block cipher."
|
12
|
-
spec.homepage = "https://codeberg.org/htp/present-cipher"
|
13
|
-
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">= 2.6.0"
|
15
|
-
|
16
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
-
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://codeberg.org/htp/present-cipher"
|
20
|
-
spec.metadata["changelog_uri"] = "https://codeberg.org/htp/present-cipher/blob/main/CHANGELOG.md"
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(__dir__) do
|
25
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
end
|