Professional Documents
Culture Documents
When encrypting, a person looks up each letter of the message in the "plain" line
and writes down the corresponding letter in the "cipher" line.
Caesar cipher
MATLAP Application
Code:
%% caesar cipher
Plaintext= input('Plaintext: ','s')
%% text the user want to encrypt
Shift= input('Shift: ')
%% user choose the number of shift
Output = Plaintext+Shift;
r=Output-26;
for i = 1:length(Plaintext)
if Output(i) <= 30
Output(i) = char(Output(i));
else
Output(i) = char(r(i));
end
end
fprintf('Ciphertext: ','s')
disp(char(Output))
Run:
EX(1):
When we entered (plaintext) :
Shift = 15
Ciphertext: hVabVc
Shift = 15
Ciphertext : hVabVc
Summary:
The Different between ex 1 and ex 2 :
same the shift for ex1 and ex2 , like that plaintext but for ex1 we did space in word end
if I enter plaintext = hvabvc and same the shift he gives the ciphertext = salman
but if change any plaintext or shift the output for ciphertext is different
References: