Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Chaocipher/Ruby/chaocipher.rb
Normal file
19
Task/Chaocipher/Ruby/chaocipher.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
txt = "WELLDONEISBETTERTHANWELLSAID"
|
||||
@left = "HXUCZVAMDSLKPEFJRIGTWOBNYQ".chars
|
||||
@right = "PTLNBQDEOYSFAVZKGJRIHWXUMC".chars
|
||||
|
||||
def encrypt(char)
|
||||
coded_char = @left[@right.index(char)]
|
||||
|
||||
@left.rotate!(@left.index(coded_char))
|
||||
part = @left.slice!(1,13).rotate
|
||||
@left.insert(1, *part)
|
||||
|
||||
@right.rotate!(@right.index(char)+1)
|
||||
part = @right.slice!(2,12).rotate
|
||||
@right.insert(2, *part)
|
||||
|
||||
@left[0]
|
||||
end
|
||||
|
||||
puts txt.each_char.map{|c| encrypt(c) }.join
|
||||
Loading…
Add table
Add a link
Reference in a new issue