0% found this document useful (0 votes)
68 views

Network Security - Programs: Workshop On Communication Networks 6 - 7 January 2017

The document provides information on network security programs and examples of monoalphabetic and polyalphabetic substitution ciphers, including shift cipher, autokey cipher, and Hill cipher. It also discusses transposition ciphers and provides examples of a keyless columnar transposition cipher and a keyed columnar transposition cipher. The document was prepared by Mr. G. Balamurugan for a workshop on communication networks.

Uploaded by

vijai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Network Security - Programs: Workshop On Communication Networks 6 - 7 January 2017

The document provides information on network security programs and examples of monoalphabetic and polyalphabetic substitution ciphers, including shift cipher, autokey cipher, and Hill cipher. It also discusses transposition ciphers and provides examples of a keyless columnar transposition cipher and a keyed columnar transposition cipher. The document was prepared by Mr. G. Balamurugan for a workshop on communication networks.

Uploaded by

vijai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Workshop on

Communication Networks
th th
6 – 7 January 2017

Network Security –
Programs

Prepared by
Mr.G.Balamurugan
Assistant Professor,
Electronics Department, MIT Campus, Anna University

Workshop on Communication Networks CEG - 2017 Page 1


Network Security:

Substitution Cipher: In substitution cipher replaces one symbol with another. If the symbols
in the plaintext are alphabetic characters then replace one character with another. If the
symbols are digits we can replace with another digit.

(a) Mono-alphabetic cipher: A character in the plain text is always changed to same
character in the cipher text regardless of its position in the text. Ex: Letter A is
changed to letter D, every letter A is changed to letter D. Relationship between letters
in the plain text and the cipher text is one to one.

Example: Shift cipher.

Ex: 1 Shift Cipher

Aim: To ensure security by converting the given text into encrypted code using Mono-
alphabetic substitution cipher.

Formulae:
Encryption algorithm is “shift key characters down”
C=(M+K) mod 26

Decryption algorithm is “shift key characters up”


M=(C-K) mod 26

Workshop on Communication Networks CEG - 2017 Page 2


Program:
%% ----------------- Monalphabatic - Shift cipher -------------------------
plaintext=input('Enter the message : ','s');
key=input('Enter key value:');

%% Encryption
plainASCII=abs(plaintext); % To convert to ASCII values
alphapos=mod(plainASCII,65); % To find the position of the character
cipher=alphapos+key;
ciphertext=mod(cipher,26)+65; % Character position to ASCII value
sprintf('Encrypted text : %s',char(ciphertext))

%% Decryption
decrypos=mod(ciphertext,65);
decrypt=decrypos-key;
decrypttext=mod(decrypt,26)+65;
sprintf('Decrypted text : %s',char(decrypttext))

(b) Poly-alphabetic cipher: Each occurrence of a character can have a different substitute.
The relationship between a character in the plaintext to a character in the cipher text is one to
many. For example A could be changed to letter C in the beginning of the text, but as N at the
middle.

Advantage: Poly-alphabetic cipher is hiding the letter of the underlying language. Eve cannot
use single letter frequency statistic to break the cipher text.

Example: Auto Key cipher, Hill Cipher

Ex: 2 Auto-key Cipher

Aim: To ensure security by converting the given text into encrypted code using Auto-key
cipher (poly-alphabetic Substitution).

Formulae:
Plaintext (P)=[ p1 p2 p3 p4 p5..... pm ]
Ciphertext (C)= [ c1 c2 c3 c4 c5..... cm ]
Key (K)= [ k1,p1, p2, p3, p4, p5..... pm-1 ]

Encryption algorithm: Ci=(Pi + Ki) mod 26


Decryption algorithm: Pi=(Ci - Ki) mod 26

Program:
%% ----------- Substitution Cipher (Poly-alphabetic) - Auto key cipher ----
plaintext=input('Enter the message : ','s');
key=[];
key=input('Enter key value:');

Workshop on Communication Networks CEG - 2017 Page 3


%% Encryption algorithm
plaintextpos=mod(plaintext,65);
tempkey=plaintextpos(1:length(plaintext)-1);
autokey=key;
autokey(1,2:length(plaintext))=tempkey;
ciphertextWOC=plaintextpos+autokey;
ciphertextWC=mod(ciphertextWOC,26);
ciphertext=char(ciphertextWC+65);
fprintf('Encrypted text : %s\n',ciphertext)

%% Decryption algorithm
ciphertextpos=mod(ciphertext,65);
decipher=[];
for i=1:length(ciphertextpos)
dicpher(i)=mod(ciphertextpos(i)-key,26);
key=dicpher(i);
end
dicphertext=char(dicpher+65);
fprintf('Decrypted text : %s\n',dicphertext)

Ex: 3 Hill Cipher

Aim: To ensure security by converting the given text into encrypted code using Hill cipher
(poly-alphabetic Substitution).

Theory:

The plaintext is divided into equal size blocks. The blocks are encrypted one at a time in such
a way that each character in the block contributes to the encryption of other character
characters in the block. For this reason, Hill cipher belongs to a category of ciphers called
block ciphers. In a Hill cipher, the key is a square matrix of size MxM in which M is the size
of the block.

Formulae:
Encryption: C=PK mod 26

Decryption: P=CK-1 mod 26

Workshop on Communication Networks CEG - 2017 Page 4


Program:
clear all;
clc;
%% -------- Substitution Cipher (Poly-alphabatic) - Hill cipher ----------

plaintext=input('Enter the message : ','s');


charpos=abs(plaintext)-65;
key=[5 8;17 3];
%key=[17 17 5; 21 18 21;2 2 19]
inversekey=[9 2; 1 15];
%inversekey=[4 9 15; 15 17 6; 24 0 17];

%% Initialize the block


N=size(key,1);
D=length(plaintext);

% Find the number Letters to pad in a block


if mod(D,N)== 0
pad=0;
else
pad=N-mod(D,N);
end

% Padding characters 'Z' at the end of the message


for i=1:pad
plaintext=[plaintext 'Z'];
end

%% Encryption Algorithm

plaintextblock=reshape(plaintext,2,[])';
plaintextpos=mod(plaintextblock,65);
ciphervalue=mod(plaintextpos*key,26);
cipher=reshape(ciphervalue',1,[]);
ciphertext=char(cipher+65);
fprintf('Encrypted text : %s\n',ciphertext)

%% Decryption Algorithm

receiver=reshape(ciphertext,2,[])';
receivertextpos=mod(receiver,65);
decipherpos=mod(receivertextpos*inversekey,26);
decipher=char(decipherpos+65);
deciphertext=reshape(decipher',1,[]);
fprintf('Decrypted text : %s\n',deciphertext);

Transposition Cipher: It does not substitute one symbol for another; instead it changes the
location of the symbols. A symbol in the first position of the plaintext may appear in the tenth
position of the cipher. In other words, a transposition cipher reorders the symbols.

Keyless Transposition cipher: The text is written into a table row by row and then transmitted
column by column.

Workshop on Communication Networks CEG - 2017 Page 5


Keyed Transposition cipher: The keyed ciphers permute the characters by writing the
plaintext in one way (row by row) and reading it in another way (column by column). The
permutation is done on the whole plain text to create the whole cipher text.

For both cipher first divide the plaintext into groups of predetermined size called blocks and
then use a key to permute the characters in each block separately.

Ex: 4 Keyless Columnar Transposition Cipher

Aim: To encrypt and decrypt the given message by using keyless columnar transposition
cipher.

Formulae:
Block Grid size 5

Keyless Transposition cipher: The text is written into a table row by row and then transmitted
column by column.

Program:
clear all
clc

%% ---- Transposition Cipher - Keyless Columnar Transposition cipher -----


%plain_txt=input('Enter the message : ','s');
N=5; % Key (5x5)
plain_txt='ABCDEFGHIJKLMNOPQRSTXYZABCDEFGHIJKLMNO';

%% Read the plaintext from the text file


% add='plain.txt';
% f_file = fopen(add, 'r');
% plain_txt = fscanf(f_file, '%c');
% fclose(f_file);

%% Initialize the block

NN=N*N; % Number of characters in a block


D=length(plain_txt);

% Find the number Letters to pad in a block


if mod(D,NN)== 0
pad=0;
else
pad=NN-mod(D,NN);
end

% Padding characters 'Z' at the end of the message


for i=1:pad
plain_txt=[plain_txt 'Z'];
end

Workshop on Communication Networks CEG - 2017 Page 6


%% Encryption Block
cipher_txt=[];
PlaintextBlock =reshape(plain_txt,5,[])';
for i=1:1:length(plain_txt)/NN
ff=PlaintextBlock(((i*N)-(N-1)):i*N,1:N);
cipher_txt=[cipher_txt reshape(ff,1,[])]; % reading character column by
column
end
fprintf('Encrypted text : %s\n',cipher_txt)

%% Save the encrypted text in a file.


% f_file = fopen('trans_encryp.txt', 'w');
% fprintf(f_file, '%c',cipher_data);
% fclose(f_file);

%% Decryption algorithm
Decipher_txt=[];
cipher_txtBlock =reshape(cipher_txt,5,[])';
for i=1:1:length(cipher_txt)/NN
ff=cipher_txtBlock(((i*N)-(N-1)):i*N,1:N);
Decipher_txt=[Decipher_txt reshape(ff,1,[])]; % reading character column by
column
end
fprintf('Decrypted text : %s\n',Decipher_txt)

%% Save the decrypted text in a file.


% f_file = fopen('trans_decrypt.txt', 'w');
% fprintf(f_file, '%c',decipher_data);
% fclose(f_file);

Ex: 5 Keyed Columnar Transposition Cipher

Aim: To encrypt and decrypt the given message by using keyed columnar transposition
cipher.

Formulae:
Key= [ 2 1 5 3 4]

Keyed Transposition cipher: The keyed ciphers permute the characters by writing the
plaintext in one way (row by row) and reading it in another way (column by column) by
using key. The permutation is done on the whole plain text to create the whole cipher text.

Program:
clear all
clc

%% ----------- Transposition Cipher - Columnar Transposition cipher -------


plain_txt=input('Enter the message : ','s');
N=5; % Key (5x5)
%plain_txt='ABCDEFGHIJKLMNOPQRSTXYZABCDEFGHIJKLMNO';

%% Read the plaintext from the text file

Workshop on Communication Networks CEG - 2017 Page 7


% add='plain.txt';
% f_file = fopen(add, 'r');
% plain_txt = fscanf(f_file, '%c');
% fclose(f_file);

%% Initialize the block

NN=N*N; % Number of characters in a block


D=length(plain_txt);

% Find the number Letters to pad in a block


if mod(D,NN)== 0
pad=0;
else
pad=NN-mod(D,NN);
end

% Padding characters 'Z' at the end of the message


for i=1:pad
plain_txt=[plain_txt 'Z'];
end

%% Encryption Block
cipher_txt=[];
PlaintextBlock =reshape(plain_txt,5,[])';
for i=1:1:length(plain_txt)/NN
ff=PlaintextBlock(((i*N)-(N-1)):i*N,1:N);
ffwithkey=ff(1:5,[2, 1 ,5 ,3, 4])
cipher_txt=[cipher_txt reshape(ffwithkey,1,[])]; % reading character
column by column
end
fprintf('Encrypted text : %s\n',cipher_txt)

%% Save the encrypted text in a file.


% f_file = fopen('trans_encryp.txt', 'w');
% fprintf(f_file, '%c',cipher_data);
% fclose(f_file);

%% Decryption algorithm
Decipher_txt=[];
cipher_txtBlock =reshape(cipher_txt,5,[]);
for i=1:1:length(cipher_txt)/NN
ffcipher=cipher_txtBlock(1:N,((i*N)-(N-1)):i*N);
ffcipherwithkey=ffcipher(1:5,[2 1 4 5 3]);
Decipher_txt=[Decipher_txt reshape(ffcipherwithkey',1,[])]; % reading
character column by column
end
fprintf('Decrypted text : %s\n',Decipher_txt)

%% Save the decrypted text in a file.


% f_file = fopen('trans_decrypt.txt', 'w');
% fprintf(f_file, '%c',decipher_data);
% fclose(f_file);

Workshop on Communication Networks CEG - 2017 Page 8


Ex: 6 Advanced Encryption Standard (AES)

AIM: To implement the Advanced encryption standard using MATLAB

Theory:
The Advanced Encryption Standard (AES) is symmetric key algorithm, meaning same key is
used for both encrypting and decrypting the data. AES is based on a design principle of
known as substitution and permutation. AES has a fixed block size of 128bits and a key size
of 128, 192 or 256 bits. Encryption consists of 10 rounds of processing for 128-bit keys, 12
rounds for 192-bit keys, and 14 rounds for 256-bit keys. Except for the last round in each
case, all other rounds are identical.

Steps involved in each round:


1. Sub Bytes
2. Shift rows
3. Mix columns
4. Add Round key

STEP 1: In sub Bytes, each byte in the state is replaced by 8-bit look-up table called
substitution box (S-Box).

STEP 2: In shift row, the bytes in each row of the state are shifted cyclically to the left. The
number of places each byte is shifted differs for each row.
1St Row : Row is left unchanged
2nd Row: Each byte of the row is shifted one to the left
3rd Row: Each byte of the row is shifted twice to the left
4th Row: Each byte of the row is shifted thrice to the left

Workshop on Communication Networks CEG - 2017 Page 9


STEP 3: In Mix columns, each column of the state is multiplied with a known matrix.

The multiplication operation is defined as


multiplication by 1 means leaving unchanged,
multiplication by 2 means shifting byte to the left ,
multiplication by 3 means shifting byte to the left ,
and then performing XOR with the initial unshifted value.

After shifting, a conditional XOR with 0x1B should be performed if the shifted value is
larger than 0xFF.

STEP 4: In Add Round key, each byte of the state is combined with a byte of the round sub
key using XOR operation. For each round, a sub key is derived from the main key using
Rijndael’s key schedule.

Key Generation:

 RotWord performs a one byte circular left shift on a word


 SubWord performs a byte substitution on each byte of input word using the S-box
 SubWord and RCon[j] is XORed to generate next key word.

Program:
ssi;
plaintext=['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O'
'P'];
plain=reshape(plaintext,4,4);
plain = abs (plain) % Converts to ASCII value
key = ['1' '2' '3' '4' '5' '6' '7' '8' '9' '1' '2' '3' '4' '5' '6' '7'];
key=abs(key);
w = key_expansion (key, s_box, rcon);

% Encryption
ciphertext = cipher (plain, w, s_box, poly_mat,ind_matleft);
ciphertext = reshape(ciphertext,1,16);

Workshop on Communication Networks CEG - 2017 Page 10


ciphertext = char(ciphertext)

% Decryption
deciphertext = reshape (double(ciphertext), 1, 16);
deciphertext =reshape(deciphertext,4,4);
deciphertext = decipher (deciphertext, w, inv_s_box,
inv_poly_mat,ind_matright)

%% Key generation [W0 – W43].


function w = key_expansion (key, s_box, rcon)
w = (reshape (key, 4, 4))';
for i = 5 : 44
temp = w(i - 1, :);
if mod (i, 4) == 1
temp = temp([2 3 4 1]);
temp = s_box(temp+1);
r = rcon ((i - 1)/4, :);
temp = bitxor (temp, r);
end
w(i, :) = bitxor (w(i - 4, :), temp);
end

function ciphertext = cipher (plaintext, w, s_box, poly_mat,ind_matleft)


%state = reshape (plaintext, 4, 4)
state = plaintext
round_key = (w(1:4, :))';
state = bitxor(round_key,state);
for i_round = 1 : 9
state = s_box (state + 1);
state = state(ind_matleft); % Shifting rows
state = mix_columns (state, poly_mat);
round_key = (w((1:4) + 4*i_round, :))';
state = bitxor (state, round_key);
end
state = s_box (state+1);
state = state(ind_matleft);
round_key = (w(41:44, :))';
ciphertext = bitxor (state, round_key);

function deciphertext = decipher (plaintext, w, inv_s_box,


inv_poly_mat,ind_matright)
state = plaintext
round_key = (w(41:44, :));
state = bitxor (state, round_key);
for i_round = 9 :-1: 1
state = state(ind_matright); % Shifting rows
state = inv_s_box (state + 1); % Inv Sub Bytes
round_key = (w((1:4) + 4*i_round, :)); % Add Round key
state = bitxor (state, round_key);
state = mix_columns (state, inv_poly_mat); % Inverse Mix column
end
state = state(ind_matright); % Shifting rows
state = inv_s_box (state + 1);
round_key = (w((1:4), :)); % Add Round key
deciphertext = bitxor (state, round_key);

Workshop on Communication Networks CEG - 2017 Page 11


function state_out = mix_columns (state_in, poly_mat)
mod_pol = bin2dec ('100011011');
for i_col_state = 1 : 4
for i_row_state = 1 : 4
temp_state = 0;
for i_inner = 1 : 4
temp_prod = poly_mult (...
poly_mat(i_row_state, i_inner), ...
state_in(i_inner, i_col_state), ...
mod_pol);
temp_state = bitxor (temp_state, temp_prod);
end
state_out(i_row_state, i_col_state) = temp_state;
end
end

function ab = poly_mult (a, b, mod_pol)


ab = 0;
for i_bit = 1 : 8
if bitget (a, i_bit)
b_shift = bitshift (b, i_bit - 1);
ab = bitxor (ab, b_shift);
end
end
for i_bit = 16 : -1 : 9
if bitget (ab, i_bit)
mod_pol_shift = bitshift (mod_pol, i_bit - 9);
ab = bitxor (ab, mod_pol_shift);
end
end

s_box = [
99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171,
118, ...
202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114,
192, ...
183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49,
21, ...
4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178,
117, ...
9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47,
132, ...
83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88,
207, ...
208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159,
168, ...
81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243,
210, ...
205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25,
115, ...
96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11,
219, ...
224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228,
121, ...
231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174,
8, ...
186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139,
138, ...

Workshop on Communication Networks CEG - 2017 Page 12


112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29,
158, ...
225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40,
223, ...
140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187,
22];

inv_s_box = [
82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215,
251, ...
124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233,
203, ...
84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195,
78, ...
8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209,
37, ...
114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, 204, 93, 101, 182,
146, ...
108, 112, 72, 80, 253, 237, 185, 218, 94, 21, 70, 87, 167, 141, 157,
132, ...
144, 216, 171, 0, 140, 188, 211, 10, 247, 228, 88, 5, 184, 179, 69,
6, ...
208, 44, 30, 143, 202, 63, 15, 2, 193, 175, 189, 3, 1, 19, 138,
107, ...
58, 145, 17, 65, 79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230,
115, ...
150, 172, 116, 34, 231, 173, 53, 133, 226, 249, 55, 232, 28, 117, 223,
110, ...
71, 241, 26, 113, 29, 41, 197, 137, 111, 183, 98, 14, 170, 24, 190,
27, ...
252, 86, 62, 75, 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90,
244, ...
31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236,
95, ...
96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156,
239, ...
160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153,
97, ...
23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12,
125];

inv_poly_mat = [
14,11, 13, 9,
9, 14, 11, 13,
13, 9, 14, 11,
11, 13, 9, 14];

poly_mat = [2,3,1,1,
1,2,3,1,
1,1,2,3,
3,1,1,2];

rcon=[ 1 0 0 0
2 0 0 0
4 0 0 0
8 0 0 0
16 0 0 0
32 0 0 0

Workshop on Communication Networks CEG - 2017 Page 13


64 0 0 0
128 0 0 0
27 0 0 0
54 0 0 0];

ind_matleft =[

1 5 9 13
6 10 14 2
11 15 3 7
16 4 8 12];

ind_matright =[1 5 9 13
14 2 6 10
11 15 3 7
8 12 16 4];

Ex: 7 Public key Cryptosystem - (RSA)

Aim: To implement the RSA algorithm using MATLAB

RSA algorithm example


1. Choose p=3 and q=11
2. Compute n = p * q = 3 * 11 = 33
3. Compute φ(n)= (p – 1) * (q – 1) = 2 * 10 = 20
4. Choose e such that 1 < e < φ(n) and e and n are coprime. Let e=7
5. Compute a value for d such that (d * e) % φ(n)=1. One solutions is d = 3 [3(3 * 7)
%20=1]
6. Public key is (e,n) => (7,33)
7. Private key is (d,n) => (3,33)
7
8. The encryption of m = 2 is c = 2 % 33 = 29
3
9. The decryption of c = 29 id m =29 % 33 = 2

Program:
clc;
clear all;
close all;

%% To get prime numbers from user


p=input('enter the value for p: ');
q=input('enter the value for q: ');
n=p.*q;
phi=(p-1).*(q-1);

%% To find Public key


for i=2:(phi-1)
if(gcd(i,phi)==1)
e=i;
break;
end
end
disp('the public key e is found ');
disp(e);

Workshop on Communication Networks CEG - 2017 Page 14


%% To find private key
d=modinv(e,phi);
disp('the private key d is found');
disp(d);

%% Obtaining message from user


m=input('enter the message: ','s');
%ch=char(m);
%ascii=unicode2native(ch);
ascii=abs(ch);
disp('the ascii value of the entered data is as follows: ');
disp(ascii);

%% Encryption Algorithm
k=1;
g=0;
while(g<e)
g=g+1;
k=mod(m.*k,n)
end
c=k;
disp('the ascii value of the encrypted message is as follows: ');
disp(c);
cipher=char(c);
disp('the encrypted message is as follows: ');
disp(cipher);

%% Decryption Algorithm
k=1;
g=0;
while(g<d)
g=g+1;
k=mod(c.*k,n);
end
deascii=k;
disp('the ascii value of the decrypted message is as follows: ');
disp(deascii);
desrypt_message=char(deascii);
disp('the decrypted message is as follows: ');
disp(desrypt_message);

%%
if(isempty(d))
disp('the inverse does not exist for the data!!!!!!');
end

%% To calculate modulo inverse


function [d]=modinv(e,phi)
d=[];
for k=0:(phi-1)
if(mod((e.*k),phi)==1)
d=k;
break;
end
end

Workshop on Communication Networks CEG - 2017 Page 15

You might also like