Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Caesar-cipher/Eiffel/caesar-cipher.e
Normal file
53
Task/Caesar-cipher/Eiffel/caesar-cipher.e
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
ARGUMENTS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Run application.
|
||||
local
|
||||
s: STRING_32
|
||||
do
|
||||
s := "The tiny tiger totally taunted the tall Till."
|
||||
print ("%NString to encode: " + s)
|
||||
print ("%NEncoded string: " + encode (s, 12))
|
||||
print ("%NDecoded string (after encoding and decoding): " + decode (encode (s, 12), 12))
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
decode (to_be_decoded: STRING_32; offset: INTEGER): STRING_32
|
||||
-- Decode `to be decoded' according to `offset'.
|
||||
do
|
||||
Result := encode (to_be_decoded, 26 - offset)
|
||||
end
|
||||
|
||||
encode (to_be_encoded: STRING_32; offset: INTEGER): STRING_32
|
||||
-- Encode `to be encoded' according to `offset'.
|
||||
local
|
||||
l_offset: INTEGER
|
||||
l_char_code: INTEGER
|
||||
do
|
||||
create Result.make_empty
|
||||
l_offset := (offset \\ 26) + 26
|
||||
across to_be_encoded as tbe loop
|
||||
if tbe.item.is_alpha then
|
||||
if tbe.item.is_upper then
|
||||
l_char_code := ('A').code + (tbe.item.code - ('A').code + l_offset) \\ 26
|
||||
Result.append_character (l_char_code.to_character_32)
|
||||
else
|
||||
l_char_code := ('a').code + (tbe.item.code - ('a').code + l_offset) \\ 26
|
||||
Result.append_character (l_char_code.to_character_32)
|
||||
end
|
||||
else
|
||||
Result.append_character (tbe.item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue