Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.68 KB | None | 0 0
  1. class Jawne
  2.   def initialize (napis)
  3.     @napis = napis
  4.   end
  5.  
  6.   def zaszyfruj (klucz)
  7.     res = ""
  8.     for c in 0 .. @napis.length-1 do
  9.       res+= klucz[ @napis[c] ]
  10.     end
  11.     return Zaszyfrowane.new(res)
  12.   end
  13.  
  14.   def to_s
  15.     return @napis
  16.   end
  17. end
  18.  
  19. class Zaszyfrowane
  20.   def initialize (napis)
  21.     @napis=napis
  22.   end
  23.  
  24.   def odszyfruj(klucz)
  25.     res = ""
  26.     for c in 0 .. @napis.length-1 do
  27.       res+= klucz[ @napis[c] ]
  28.     end
  29.     return Odszyfrowane.new(res)
  30.   end
  31.  
  32.   def to_s
  33.     return @napis
  34.   end
  35. end
  36.  
  37. print("zad.3\n")
  38. klucz1 = {
  39.   'a' => 'b',
  40.   'b' => 'c',
  41.   'c' => 'd'
  42. }
  43. j = Jawne.new("abc")
  44. puts(j.to_s)
  45. puts(j.zaszyfruj(klucz1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement