-
Notifications
You must be signed in to change notification settings - Fork 2
/
Caesar-Cipher.pas
61 lines (60 loc) · 1.7 KB
/
Caesar-Cipher.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{$mode objfpc} // directive to be used for defining classes
program caesarCipherClass;
type
(*
* @file Class realize Caesar encryption metods.
* @class caesarCipher
* @author Full_droper <full_droper@pm.me>
* @version 0.0.1
*)
caesarCipher = class
public
constructor create();
(**
* Encode input data by Caesar Cipher.
* @name encode
* @param {object} rawData - raw data for encode.
* @param {number} key - (default 1) count of shift.
* @return {object} The encoded by Caesar Cipher data
*)
function encode(rawData:string; key: cardinal): string;
(**
* Decode input data by Caesar Cipher.
* @name decode
* @param {object} rawData - raw data for decode.
* @param {number} key - (default 1) count of shift.
* @return {object} The decoded by Caesar Cipher data
*)
function decode(rawData:string; key: cardinal): string;
end;
var
// temp vars
World, str1, str2: string;
conv : caesarCipher;
constructor caesarCipher.create();
begin
// nothing
end;
function caesarCipher.encode(rawData:string; key: cardinal): string;
var
i : Integer;
begin
for i := 1 to length(rawData) do
rawData[i] := Chr(ord(rawData[i]) + key);
encode := rawData;
end;
function caesarCipher.decode(rawData:string; key: cardinal): string;
var
i : Integer;
begin
for i := 1 to length(rawData) do
rawData[i] := Chr(ord(rawData[i]) - key);
decode := rawData;
end;
begin
conv := caesarCipher.create();
World := 'Hello World';
str1 := conv.encode(World, 2);
str2 := conv.decode(str1, 2);
write (World,' -> ',str1,' -> ',str2);
end.