-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaeserEncr.m
34 lines (24 loc) · 875 Bytes
/
CaeserEncr.m
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
function [cipherStr] = CaeserEncr(plaintext)
na = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' '];
nac = ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'A', 'B'];
S = size(plaintext);
SIZE = S(2);
cipher = [];
SIZE_cipher = 0;
%%converts the list of numbers to an array
for i = 1:SIZE %%i is the ith char
for j = 1:27 %% j is the jth element in na
if plaintext(i) == na(j)
s = size(cipher);
SIZE_cipher = s(2);
cipher(SIZE_cipher + 1) = j;
SIZE_cipher = SIZE_cipher + 1;
end
end
end
cipherStr = '';
for i = 1:SIZE_cipher
s = size(cipherStr);
cipherStr(s(2) + 1) = nac(cipher(i));
end
end