rsa-encrypter 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rsa-encrypter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Cevin Eichnau
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Rsa::Encrypter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rsa-encrypter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rsa-encrypter
18
+
19
+ ## Usage
20
+
21
+ example to use :
22
+
23
+ key = generate_rsa
24
+
25
+ puts "your message ?"
26
+ print "=> "; m = gets.chomp
27
+
28
+ e = encrypt(m, key[1], key[0])
29
+
30
+ puts decrypt(e, key[2], key[0])
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,80 @@
1
+ require "rsa-encrypter/version"
2
+
3
+ module Rsa
4
+ module Encrypter
5
+ def self.ggt(a, b)
6
+ u=t=1
7
+ v=s=0
8
+ while b > 0 do
9
+ q=a/b
10
+ a, b = b, a-q*b
11
+ u, s = s, u-q*s
12
+ v, t = t, v-q*t
13
+ end
14
+ return u
15
+ end
16
+
17
+ def self.prime?(x)
18
+ if x == 0 or x == 1
19
+ return false
20
+ end
21
+
22
+ i = 2
23
+ limit = x / i
24
+ while i < limit
25
+ if x % i == 0
26
+ raise "1 of 2 nubers dont prime"
27
+ end
28
+ i += 1
29
+ limit = x / i
30
+ end
31
+ return x
32
+ end
33
+
34
+ def self.generate_rsa
35
+
36
+ p = prime?(1033)
37
+ q = prime?(977)
38
+ n = p * q
39
+ n2 = (p-1)*(q-1)
40
+ e = (p+q) -1
41
+ t = ggt(e, n2)
42
+ d = t
43
+ rsa = [n, e, d]
44
+ return rsa
45
+ end
46
+
47
+ def self.encrypt(message, e, n)
48
+ byte = []
49
+ ms = []
50
+ crypt = []
51
+ message.each_char do |c|
52
+ byte << c.ord
53
+ end
54
+ byte.each do |b|
55
+ if b.to_s.length < 3
56
+ ms << "0"+b.to_s
57
+ else
58
+ ms << b
59
+ end
60
+
61
+ end
62
+
63
+
64
+ ms.each do |b|
65
+ crypt << c = b.to_i**e % n
66
+ end
67
+
68
+ return crypt
69
+ end
70
+
71
+ def self.decrypt(message, d, n)
72
+ m = ""
73
+ message.each do |c|
74
+ m += (c**d % n).to_i.chr
75
+ end
76
+ return m
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module Rsa
2
+ module Encrypter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rsa-encrypter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rsa-encrypter"
8
+ gem.version = Rsa::Encrypter::VERSION
9
+ gem.authors = ["Cevin Eichnau"]
10
+ gem.email = ["cevin@empuxa.com"]
11
+ gem.description = %q{rsa-encrypter to encrypt messages like password usw}
12
+ gem.summary = %q{ its a rsa-encrypter they use a private and public key to encrypt and decrypt messages}
13
+ gem.homepage = "http://eichnau.com/posts/96"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsa-encrypter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cevin Eichnau
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: rsa-encrypter to encrypt messages like password usw
15
+ email:
16
+ - cevin@empuxa.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/rsa-encrypter.rb
27
+ - lib/rsa-encrypter/version.rb
28
+ - rsa-encrypter.gemspec
29
+ homepage: http://eichnau.com/posts/96
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.25
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: its a rsa-encrypter they use a private and public key to encrypt and decrypt
53
+ messages
54
+ test_files: []