Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 3.43 KB | None | 0 0
  1. note
  2.     description: "Summary description for {CIPHER}."
  3.     author: ""
  4.     date: "$Date$"
  5.     revision: "$Revision$"
  6.  
  7. class
  8.     CIPHER
  9.  
  10. feature
  11.  
  12.     arr: ARRAY2[CHARACTER]
  13.  
  14.     k_str(k, tx: STRING): STRING
  15.     local
  16.         i: INTEGER
  17.         j: INTEGER
  18.         new_k: STRING
  19.     do
  20.         from
  21.             i := 1
  22.             j := 0
  23.             new_k := ""
  24.         until
  25.             i = tx.count+1
  26.         loop
  27.             if(tx.item (i).code > 64 and tx.item (i).code < 91) then
  28.                 new_k.append_character (k.item (j \\ k.count + 1))
  29.                 j := j + 1
  30.             else
  31.                 new_k.append_character (tx.item (i))
  32.             end
  33.             i := i + 1
  34.         end
  35.         Result := new_k
  36.  
  37.     end
  38.  
  39.     decrypt(k, tx: STRING): STRING
  40.     local
  41.         i: INTEGER
  42.         new_str: STRING
  43.     do
  44.         from
  45.             i := 1
  46.             new_str := ""
  47.         until
  48.             i = tx.count+1
  49.         loop
  50.             if(tx.item (i).code > 64 and tx.item (i).code < 91 and k.item (i).code > 64 and k.item (i).code < 91) then
  51.                 new_str.append_character((((tx.item (i).code + k.item (i).code - (65*2))\\26) + 65).to_character)
  52.             else
  53.                 new_str.append_character (tx.item (i))
  54.             end
  55.             i := i + 1
  56.         end
  57.         Result := new_str
  58.  
  59.     end
  60.  
  61.     box(str: STRING): STRING
  62.     local
  63.  
  64.         exp: BOOLEAN
  65.         i: INTEGER
  66.         j: INTEGER
  67.         k: INTEGER
  68.         z: INTEGER
  69.         str1: STRING
  70.         x: INTEGER
  71.         times: INTEGER
  72.         q: INTEGER
  73.     do
  74.         str1 := ""
  75.         x := 0
  76.         times := 1
  77.         from
  78.             i := 1
  79.             exp := true
  80.         until
  81.             exp = false
  82.         loop
  83.             if(i*i <= str.count) then
  84.                 i := i + 1
  85.             else
  86.                 exp := false
  87.             end
  88.         end
  89.  
  90.         create arr.make_filled ('*', i, i)
  91.         from
  92.             j := 1
  93.             z := 1
  94.         until
  95.             j > i
  96.         loop
  97.             from
  98.                 k := 1
  99.             until
  100.                 k > i
  101.             loop
  102.                 if((z > str.count) = false) then
  103.                     arr.put (str.item (z), j, k)
  104.  
  105.                 end
  106.                 k := k + 1
  107.                 z := z + 1
  108.             end
  109.             j := j + 1
  110.  
  111.         end
  112.  
  113.  
  114.         from k:=1
  115.         until k>i
  116.         loop
  117.             from j:=1
  118.             until j>i
  119.             loop
  120.                 print (arr.item (k, j)) print (" ")
  121.                 j:=j+1
  122.             end
  123.             k:=k+1
  124.             print("%N")
  125.         end
  126.  
  127.         from k:=i
  128.         until k<I//2
  129.         loop
  130.             str1.append_string (getRightColumn(k,i-k+1,i))
  131.  
  132.             str1.append_string (getBottomRow(k,i-k+2,i))
  133.  
  134.             str1.append_string (getLeftColumn(k,i-k+2,i))
  135.  
  136.             str1.append_string (getTopRow(k,i-k+2,i))
  137.  
  138.             k:=k-1
  139.         end
  140.  
  141.  
  142.         Result := str1
  143.     end
  144.  
  145.     getRightColumn(startind, endind, maxind: INTEGER):STRING
  146.     local
  147.         strres: STRING
  148.         j: INTEGER
  149.     do
  150.         strres:=""
  151.         from j:=startind
  152.         until j<endind
  153.         loop
  154.             if (arr.item(maxind-j+1, startind)/~'*') then
  155.                 strres.append_character(arr.item (maxind-j+1, startind))
  156.             end
  157.             j:=j-1
  158.         end
  159.         RESULT:= strres
  160.  
  161.     end
  162.  
  163.     getBottomRow(startind, endind, maxind: INTEGER):STRING
  164.     local
  165.         strres: STRING
  166.         j: INTEGER
  167.     do
  168.         strres:=""
  169.         from j:=startind
  170.         until j<endind
  171.         loop
  172.             if (arr.item(startind, j)/~'*') then
  173.                 strres.append_character(arr.item (startind, j))
  174.             end
  175.             j:=j-1
  176.         end
  177.         RESULT:= strres
  178.  
  179.     end
  180.  
  181.     getLeftColumn(startind, endind, maxind: INTEGER):STRING
  182.     local
  183.         strres: STRING
  184.         j: INTEGER
  185.     do
  186.         strres:=""
  187.         from j:=startind
  188.         until j<endind
  189.         loop
  190.             if (arr.item(j , maxind-startind+1)/~'*') then
  191.                 strres.append_character(arr.item (j, maxind-startind+1))
  192.             end
  193.             j:=j-1
  194.         end
  195.         RESULT:= strres
  196.  
  197.     end
  198.  
  199.     getTopRow(startind, endind, maxind: INTEGER):STRING
  200.     local
  201.         strres: STRING
  202.         j: INTEGER
  203.     do
  204.         strres:=""
  205.         from j:=startind
  206.         until j<endind
  207.         loop
  208.             if (arr.item(maxind-startind+1, maxind-j+1)/~'*') then
  209.                 strres.append_character(arr.item (maxind-startind+1, maxind-j+1))
  210.             end
  211.             j:=j-1
  212.         end
  213.         RESULT:= strres
  214.  
  215.     end
  216.  
  217.  
  218. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement