




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of the MATLAB commands and functions used for cryptography in the CE-408: Cryptography & Network Security course. It covers topics such as variables in MATLAB, random number generators, matrix operations, and logical operations. Students will learn how to create matrices, perform arithmetic and logical operations, and generate random numbers for cryptographic purposes.
Typology: Lab Reports
1 / 8
This page cannot be seen from the preview
Don't miss anything!





The purpose of this lab is to present the commands and function of MATLAB used for cryptography.
MATLAB (Matrix laboratory) is an interactive software system for numerical computations and graphics. A numerical analyst called Cleve Moler wrote the first version of Matlab in the 1970s. It has since evolved into a successful commercial software package. As the name suggests, Matlab is especially designed for matrix computations: solving systems of linear equations, computing eigen values and eigenvectors, factoring matrices, and so forth. In addition, it has a variety of graphical capabilities, and can be extended through programs written in its own programming language. Many such programs come with the system; a number of these extend Matlab's capabilities to nonlinear problems, such as the solution of initial value problems for ordinary differential equations. Characteristics of MATLAB:
Element extraction from a matrix. Basic functions and special matrices Creating m files and basic programs Variables in MATLAB: Type of variable in MATLAB is determined when it is created. One don’t have to declare variable before assigning it a value. There are two types of variable. i) Scalar Variables Those variables that have one (1) row and one (1) column ii) Vector Variables Vector is a matrix with wither one (1) row or one (1) column (1xn) or (nx1) iii) Matrix Variables Those variables have (n) row and (m) column (nxm) Try the following codes: Open a new m file and name it prog1 then execute the following commands: %Always use comments a = 5; % numeric variable b = [1 2 3] % A row vector which also can be written as b = [1,2,3] c = [4; 5; 6] % A column vector which also can be written as % c = [4 5 6]' where ' indicates the transpose of a matrix d = [2 4 5;3 3 3; 1 2 7] %matrix creation 3 by 3 f = [] %to create an empty matrix g = ones(3,4) %3by4 matrix with all ones h = zeros(6) %create 6by6 matrix of all zeros size(g) %finds the size of g matrix size(g,1) %finds number of rows in g size(g,2) %finds number of columns in g
r = b + c' %Addition s = g * m %matrix multiplication t = b' .* c %element wise multiplication u = o .^ 4 %each element in o is raised to power 4 det(m) %the determinant of m v = eye(4) %identity matrix of 4by %Element extraction m(2,2) %extracts the element intersection at 2nd row 2nd column in m m(1:3,2) %extracts the elements at 1 to 3 rows and 2nd column in m in %this way using the range sign : , you can extract any element %or elements depending on the intersections m(:,3) %means extract the whole 3rd column m(1,:) %means extract the whole 1st row m(:,:) %extracts the whole matrix m m(:) %arrange m in a single column vector w = [b' c d] %concatenate different matrices into a single one such that the %resultant matrix forms an acceptable shape. z = [4:0.1:5] %creates a row vector having an increment of 0. diag(l) %extracts the diagonal elements of the square matrix %Basic functions sum(d) mean(d) max(d) min(d) sin(d) cos(d)
exp(d) log(d) %for more built in functions, see the help on list of functions whos %detailed information about the variables clear d m %clears the variables d and m whos %confirm that m and d are cleared clear all %clears all currently assigned variables Logical Operations in MATLAB Many logical operations are used in cryptography for encryption and decryption. and Find logical AND not Find logical NOT or Find logical OR xor Find logical exclusive-OR Xor is most commonly used operator in cryptography. C = xor(A,B) C = xor(A,B) performs a logical exclusive-OR of arrays A and B and returns an array containing elements set to either logical 1 (true) or logical 0 (false). An element of the output array is set to logical 1 (true) if A or B, but not both, contains a nonzero element at that same array location. Otherwise, the array element is set to 0. C = bitxor(A,B) returns the bit-wise XOR of A and B. Arithmetic and Logical Shift Operators Right and left arithmetic and shift operators are used to shift the bits. c=bitsra(a,k) c=bitsra(a,k) returns the result of an arithmetic right shift by k bits on input a for fixed-point operations. For floating-point operations, it performs a multiply by 2 -k. If the input is unsigned, bitsra shifts zeros into the positions of bits that it shifts right. If the input is signed, bitsra shifts the most significant bit (MSB) into the positions of bits that it shifts right. c = bitsll(a, k)