Skip to content

Implement Ramzay cipher #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/Ramzay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Ramzay
def self.encrypt (str)
matrix = [['s','i','o','e','r','a','t','n','-','-'],
['c','x','u','d','j','p','z','b','k','q'],
['.','w','f','l','/','g','m','y','h','v']]
str = str.gsub(/ /,'/')
arr =""
str.each_byte do |c|
matrix.each_with_index do |row, i|
row.each_with_index do |a, j|
if c.chr==a
if i==0
arr<<j.to_s
else
arr<<(i+7).to_s+j.to_s
end
end
end
end
end
arr
end

def self.decrypt(str)
matrix = [['s','i','o','e','r','a','t','n','-','-'],
['c','x','u','d','j','p','z','b','k','q'],
['.','w','f','l','/','g','m','y','h','v']]
txt = ""
j = 0
str.each_byte do |c|
d = c.chr.to_i
if j==0
if d<8
txt+=matrix[0][d]
j = 0
else
if d == 8
j = 1
else
j = 2
end
end
else
txt+=matrix[j][d]
j=0
end
end
txt
end
end
2 changes: 1 addition & 1 deletion lib/aaa_crypt.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative "aaa_crypt/version"

require_relative "Ramzay"
module AaaCrypt
class Error < StandardError; end
# Your code goes here...
Expand Down
27 changes: 27 additions & 0 deletions test/Ramzay_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative "test_helper"

class Ramzay_Test < Minitest::Test
include AaaCrypt


def test_ramzay_encrypt_a
assert_equal"5", Ramzay.encrypt('a')
end

def test_ramzay_encrypt_hello_world
assert_equal"983939329491249383",
Ramzay.encrypt("hello world")
end

def test_ramzay_decrypt_a
assert_equal "a", Ramzay.decrypt("5")
end

def test_ramzay_decrypt_hello_world
assert_equal"hello/world",
Ramzay.decrypt("983939329491249383")
end

end