Encryption - Decrytption - Octave Help Codes
Encryption - Decrytption - Octave Help Codes
%Caesar Decryption
k=3; % key or no. of shifts
n=26; % key space or total no.of letters/charaters
m='KHOORZROUG'; % ciphertext
v=m-65; % convert plaintext to integers or numerical values
for n=26 and n=58. (v=m-48 for n=78)
d=mod(v-k,n); % decryption formula
char(e+65) % convert values back to letters or characters
for n=26 and n=58. [ char(e+48) for n=78 ]
Affine Cipher System
%Affine Encryption
a=5; % keys
b=8;
n=26; % key space or total no.of letters/charaters
m='HELLO'; % plaintext
v=m-65; % convert plaintext to integers or numerical values
for n=26 and n=58. (v=m-48 for n=78)
e=mod(a*v+b,n); % encryption formula
char(e+65) % convert values back to letters or characters
for n=26 and n=58. [ char(e+48) for n=78 ]
Affine Cipher System
%Finding inverse (For smaller values)
a=5; % change this according to your a
n=26; % change this according to your n
for i=1:n
if mod(a*i, n)==1;
inverse=i
end
end
%Affine Decryption
a_inv=21; % change this according to your a inverse
b=8;
n=26; % key space or total no.of letters/charaters
m='HELLO'; % plaintext
v=m-65; % convert plaintext to integers or numerical values
for n=26 and n=58. (v=m-48 for n=78)
e=mod(a_inv*(v-b),n); % decryption formula
char(e+65) % convert values back to letters or characters
for n=26 and n=58. [ char(e+48) for n=78 ]
BRUTE FORCE- Ceasar Cipher
Note:
• a is the e, and b is the phi (Φ)
• If d is negative, add it to phi to get a positive d
RSA Cipher System
Modular Exponentiation
function result = mod_exp(base, exp1, mod1)
result = 1; % Initialize result
% Rotation matrix
theta = deg2rad(45); % Convert to radians
R = [cos(theta), -sin(theta); sin(theta), cos(theta)]; %
Counterclockwise rotation matrix
% Apply rotation
rot_v = R*v