Hybrid Encryption for Securing and Tracking Goods Delivery by Multipurpose Unmanned Aerial Vehicles in Rural Areas Using Cipher Block Chaining and Physical Layer Security

[ad_1]

%———————————————

% README

%———————————————

% This is file “Test.m” used to test the proposed approach.

% The proposed approach is a framework that does not depend on a specific algorithm. It is a suggested approach for protecting transaction data logs in autonomous multiple delivery scenarios in the absence of connectivity.

% The proposed approach can be used with any symmetric encryption algorithm in the indicated encryption blocks: DES, 3DES, AES, AES-GCM, etc. It can also be used with any asymmetric encryption approach to encrypt the keys Ki and store them in the drone’s memory.

% Moreover, the proposed approach complements and does not compete with other methods, for example, AES.

% AES itself can (and generally does) use CBC in its internal operation to encrypt data (inside each one of the “Encryption” rectangles shown in Figure 3).

% Beyond this “internal” CBC inside a given “Encryption” block, what is proposed in the paper is to link the ciphertexts of each transaction via an “external” CBC in a blockchain-like fashion.

% To show how the proposed method complements, instead of competing with, other encryption techniques, we implement the proposed “external” CBC approach in conjunction with AES-256 using CBC internally (from [29]) in each “Encryption” block of Figure 3:

%

% To run this file:

% 1) Download the AES-256 Encryption code from:

% [29] David Hill (2024). AES-256 GUI using CBC mode

% (https://www.mathworks.com/matlabcentral/fileexchange/73427-aes-256-gui-using-cbc-mode) (accessed on 14 March 2024),

% MATLAB Central File Exchange.

% 2) Extract the code of the zip file from [29] into a single folder

% 3) Copy this Test file to the same folder

% 4) Save the functions rsa_keys, rsa_enc, and rsa_dec found below in the same folder

% 5) Run the file “Test.m”
%———————————————

% Examples of potential transaction texts, to be encrypted with the

% proposed approach

message(1,:) = ‘Departing from Base Command Center 123. Date 22 February 2024; Time 8:12 AM; Nb of Locations: 4; Nb of Items to deliver: 4’;

message(2,:) = ‘This is the transaction at Location 1. Date 22 February 2024; Time 8:47 AM; Item: COVID Vaccine Pack; Delivery: Successful’;

message(3,:) = ‘This is the transaction at Location 2. Date 22 February 2024; Time 9:20 AM; Item: Antibiotic; Delivery: Successful’;

message(4,:) = ‘This is the transaction at Location 3. Date 22 February 2024; Time 9:56 AM; Item: Polio Vaccine; Delivery: Successful’;

message(5,:) = ‘This is the transaction at Location 4. Date 22 February 2024; Time 10:35 AM; Item: Flu Medicine; Delivery: Successful’;

% Examples of encryption keys (in hexadecimal), to be used for encrypting

% the above messages

key(1,:) = ‘ABCDEFFEDCBA12345678900987654321ABCDEFFEDCBA12345678900987654321’;

key(2,:) = ‘12345678900987654321ABCDEFFEDCBA12345678900987654321ABCDEFFEDCBA’;

key(3,:) = ‘AAAAA678900987654321ABCDEFFEDCBA12345678900987654321ABCDEFFEDCBA’;

key(4,:) = ‘ABCDEFFEDCBA12345678900987654321ABCDEFFEDCBA12345678900987CDECDE’;

key(5,:) = ‘012DEFFEDCBA12345678900987654321ABCDEFFEDCBA12345678900987654FFF’;

% Encrypt the first message with the first key while calculating the CPU time needed:

t = cputime;

em(1,:) = Crypt(message(1,:), key(1,:));

te(1) = cputime -t; % calculate the CPU time needed

% Encrypt the rest of the messages using the proposed CBC approach: each plaintext message is

% XORed with the ciphertext of the previous message, before encrypting the result

for i=2:size(message,1)

t = cputime;

lm = length(message(i,:));xm = bitxor(typecast(uint8(message(i,:)),’int8’), typecast(uint8(em(i-1,1:lm)),’int8’));

em(i,:) = Crypt(char(xm), key(i,:));

te(i) = cputime -t;

end

%—————RSA Encryption and Decryption of the keys—————-

% The authors wrote the functions rsa_keys, rsa_enc, and rsa_dec after

% adapting/modifying the file rsa_code.m found at:

% suriyanath (2024). RSA algorithm (https://www.mathworks.com/matlabcentral/fileexchange/46824-rsa-algorithm), MATLAB Central File Exchange. Retrieved 26 February 2024.

p = 13; q = 113; % select two prime numbers

[e, d, n]= rsa_keys(p, q); % generate public and private keys

% Encrypt the symmetric encryption keys using RSA (with the Center’s public

% key (e,n)):

for i=1:size(key,1)

ek(i,:)= rsa_enc(key(i,:), e, n);

end

% After the drone returns to the Control Center:

% Decrypt the symmetric encryption keys using RSA (with the Center’s

% private key (d,n)):

for i=1:size(ek,1)
dk(i,:)= rsa_dec(ek(i,:), d, n);

end

%———————————————————————–

% Decrypt the messages using CBC: each decrypted message is

% XORed with the ciphertext of the previous message, before obtaining

% the actual result (which would correspond to the initial message):

for i=size(em,1):-1:2

t = cputime;

dm(i,:) = Decrypt(dk(i,:),em(i,:));

lm = length(message(i,:));

xm = bitxor(typecast(uint8(dm(i,:)),’int8’), typecast(uint8(em(i-1,1:lm)),’int8’));

dm(i,:) = char(xm);

td(i) = cputime -t;

end

% decrypt the last message with the last key while calculating the CPU

% time needed:

t = cputime;
dm(1,:) = Decrypt(dk(1,:),em(1,:));

td(1) = cputime -t;

% Display the results:

fprintf(‘The initial messages to be encrypted are:\n’);

message

fprintf(‘\n\n’);

fprintf(‘The encrypted messages are:\n’);

em

fprintf(‘\n\n’);

fprintf(‘The decrypted messages are:\n’);

dm

fprintf(‘\n\n’);

fprintf(‘Average CPU time for Encryption:’);

sum(te)/length(te)

fprintf(‘\n’);

fprintf(‘Average CPU time for Decryption:’);

sum(td)/length(td)

fprintf(‘\n’);

function [e, d, n]= rsa_keys(p, q)

% This function takes two prime numbers as input and produces two keys as

% output:
% Public key: e,n

% Private key: d, n

% e.g.,:

% p= 13;

% q= 113;

% n=1469

% phi(1469) is 1344

% d=367

% Public key is (271,1469)

% Private key is (367,1469)

n=p*q;

phi=(p-1)*(q-1);

val=0;

cd=0;

while(cd~=1||val==0)

n1=randi(n,1,1);

e=randi([2 n1],1,1);

val=isprime(e);

cd=gcd(e,phi);

end

val1=0;

d=0;

while(val1~=1);

d=d+1;

val1=mod(d*e,phi);

end

function [c1]= rsa_enc(m, e, n)

% This function takes a message m and a public key (e,n) as input and

% generates the RSA encrypted ciphertext c1 as output

m1=m-0;

over=length(m1);

o=1;

while(o<=over)

m=m1(o);

diff=0;

if(m>n)

diff=m-n+1;

end

m=m-diff;

qm=dec2bin(e);

len=length(qm);

c=1;

xz=1;

while(xz<=len)

if(qm(xz)==‘1’)

c=mod(mod((c^2),n)*m,n);

elseif(qm(xz)==‘0’)

c=(mod(c^2,n));

end

xz=xz+1;

end

c1(o)=c;

o=o+1;

end

function [nm1]= rsa_dec(c1, d, n)

% This function takes an RSA encrypted message c1 and a private key (e,n)

% as input and generates the decrypted message nm1 as output

over=length(c1);

o=1;

while(o<=over)

c=c1(o);

diff=0;

if(c>n)
diff=c-n+1;

end

c=c-diff;

qm1=dec2bin(d);

len1=length(qm1);

nm=1;

xy=1;

while(xy<=len1)

if(qm1(xy)==‘1’)

nm=mod(mod((nm^2),n)*c,n);

elseif(qm1(xy)==‘0’)

nm=(mod(nm^2,n));

end

xy=xy+1;

end

nm=nm+diff;

nm1(o)=char(nm);

o=o+1;

end

[ad_2]

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More