The Decryption Rsa Algorithm

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

Introduction

1.1 Introduction

The title of the project is Implement Encryption algorithms in SAC (Single Assignment C).To evaluate Single Assignment C by implementing encryption algorithms Implement the same encryption algorithm in C and evaluate encryption algorithms. As well as do the performance of both algorithms. Using the two measurement technique first is LOC (Line Of Code) and second is Time Complexity.To understand the RSA algorithm we need to understand first what is the encryption?

Cryptography is the study of techniques for communication in the secure manner in the presence of the third parties. Also in modern era it is a process of converting ordinary information into unintelligible gibberish and decryption is the reverse, in other words, moving from the unintelligible cipher text to plaintext. A cipher is a couple of algorithms that create the encryption and the reversing into decryption. The operation of a cipher is controlled by the algorithm and by the key.

In the first instance we will describe few terms: The original message is called the plaintext and the coded message is known as a cipher text.

The process of converting a plaintext to cipher text is called encryption while restoring the plain text from the cipher text is called decryption.

Algorithm is a process which generates output form input language by steps of process.

Secret Key: It is a step in process of encryption algorithm and on that base encryption algorithm performs a specific operation on plain text and generates a cipher text. The cipher text can be different on the bases of the secret key.

The process of converting plain text into cipher text by the use of algorithms is called encryption algorithms.

An algorithm which accepts cipher text and secret key and generate an original plain text by processing few steps of procedure, called a Decryption algorithm.

SAC (Single Assignment C) is a functional array of processing language which is mainly used for the numerical applications i.e. Sudoku solver, Cryptography, Image processing, etc.

The simple form of cryptography is Symmetric. The Symmetric encryption is a conventional encryption in which the encryption and decryption are performed by using the same key or the password. These algorithms are very simple and easy to operate but if third party intercepts the key then they will be able to decrypt the messages. The researchers have to develop so many different kinds of encryption algorithms because of the trustworthy e-commerce and computer file security issues. The other type is Asymmetric (public key) cryptography which as name suggest for the use of more than two persons to decrypt the message. Encryption can protect the data files on computers and storage devices.

The use of Cryptography was developed because of the secure communication. In the figure below the basic cryptography communication scenario has been described. The person X and person Y how will communicate in a secure way by the using secure communication. The person Z wants to read the message of person X and Y.

Figure 1.1 secure communication

The series of steps involved in a secure communication between X and Y.

Choose the secret key for the encryption and decryption

Input the plain text and secret key into algorithm which is encryption algorithm and generate a cipher text

Person X will send the cipher text to person Y

Put in a secret key and plain text into a decryption algorithm which will generate the plain text

Now in the case of person Z wants to read the message, He will only see the cipher text which is generated by the encryption algorithm. If person Z wants to unlock or read the cipher text, he has to have a secret key to unlock or decrypt the cipher text into plain text. But the person Z doesn’t have the key so he cannot decrypt the message. So this communication is secure between the person X and Y.

Encryption Algorithms define the rules of the encryption of the plain text and decryption of the cipher text. The cipher text of algorithms depends on the plain text and key. Now C is cipher text, K is key, P is original plain text, E is set of encryption algorithm, we can say that

C = E (K, P)

There are three main types of the encryption algorithms: Substitution cipher, stream cipher and block cipher

The substitution cipher is an encryption method by which the units of plain text will be replaced by the cipher text. Deterministic algorithm is operating on groups of bits which are called Blocks or Block Cipher that have Symmetric key (similar transformation). In stream cipher, plain text digits are used in combination with a cipher digit stream. In stream cipher which is also known as a state cipher, each plain text digit is encrypted with one at a time with the digit of the key stream. The difference between this two is, Block ciphers are operated on the large blocks of digits with a fixed and same transformation.

There are some classical types of cipher also exists such as caser cipher and Playfair cipher.

Caser Cipher: Caser cipher is invented by Julius Caesar which is substitution cipher and in this encryption algorithm letter is replaced by another letter with the help of fixed number.

Suppose we have fixed number 7, we can replace alphabets such as

Plain Text : A B C D E F G H I J K……Z

Cipher Text: G H I J K L M N O P Q…….F

Playfair Cipher: Algorithm was first used by the British army in World War I and later on it was also used by the US Army and other armed forces in World War II. Algorithm is based on 5 x 5 matrix or box. This matrix is filled with the letters according to the key or key word.

We have key "UNITED" Following the matrix which is generated according to the key word.

U

N

I

T

E

D

A

B

C

F

G

H

J

K/L

M

O

P

Q

R

S

V

W

X

Y

Z

Table: Playfair cipher matrix

Here, the keyword is UNITED. The matrix is created by filling in the letter of keyword from left hand side to right hand side and from up to down and then filling in the remainder of the matrix with the remain letters in alphabetical order. The count letters K and L as one letter. Plaintext can be encrypted two letters as same time.

The above matrix table and by knowing some rules we can cipher the plain text.

Repeating plaintext letters that are in the same pair are separated with a filler letter, such as X, so that the balloon would be treated as ba 1X 1o on.

Two plaintext letters that fall in the same row of the matrix are each replaced by the letter to the right, with the first element of the row circularly following the last. For example ,ar is encrypted as RM

Two plaintext letters that fall in the same column are each replaced by the letter beneath, with the top element of the column circularly following the last. For example , mu is encrypted as CM.

Otherwise, each plaintext letter in a pair is replaced by the letter that lies in its own row and the column occupied by the other plaintext letter. Thus, hs becomes BP and ea becomes IM.

Hill Cipher: Hill cipher was invented in 1929 by Lester Hill and it is based on the linear algebra. In these cipher method we have the key M. We can compute encryption and decryption of any plain text. The key M is in (3 X 3) matrix, C is cipher text and P is plain text,

C = PM mod 26

=

P = CK-1 mod 26

= -1mod 26

Rail Fence: Rail fence cipher is a very simple technique of a cipher. This technique through easy to crack cipher. In this technique is plain text message writing in a rectangle formats. For example we have one sentence "I will come to the university tomorrow" , now we will write in a special way "rails" suppose we have taken key here is 3.

i . . . l . . . e . . . h . . . i . . . s . . . t . . . r . . .

. w . l . c . m . t . t . e . n . v . r . i . y . o . o . r . w

. . i . . . o . . . o . . . u . . . e . . . t . . . m . . . o .

Table 1.2 Rail Fence

The table 1.2 rail fence is read the above message row by row. Here , given the key is 3. So, now the ciphertext message is :"ilehistrwlcmttenvriyoorwioouetmo".

DES (Data Encryption Standard) and RSA are both types of block cipher algorithms. DES is developed in early 1970s at IBM and is based in the earlier design by Horst feistel. It is highly influenced by the advancement of modern cryptography in academic field. RSA was invented by Ron Rivest, Adi Shamir and Leonard Adleman in 1977 at MIT and it is named on the base of their surnames first letters. We can more discuss about RSA algorithm next chapter.

1.2 Structure Of Report

If you are doing any project than this section is very important for the reader. Because of this section can give you an overview of this report structure.

Section 1 is an introduction to project. In this section I have discussed about basic of this project like encryption algorithm definition and SAC definition. As well as describing cryptography and shortly describe encryption algorithm .

In section 2 I have discussed about the RSA algorithm. This section is introduction of RSA, description of RSA. Basic step to generate the RSA algorithm like key generation, Encryption and decryption. Also I have given a simple example and as well as the security of RSA algorithm.

Section 3 is SAC (Single Assignment C). This section I have discussed about SAC. Installation of SAC, How to run SAC file and Basic operation of SAC. Lastly, I have explained similarity and difference of SAC and C through one example program.

The next section is Measurement and Performance Testing. In this section I have discussed about measure the size of RSA algorithm with LOC (Line Of Code) technique. Also I have did measurement using Time complexity and as well as did the graph of measurement complexity.

After that I have done discussion section. In this section I have written description 512-bit RSA in SAC and 64-bit RSA in C language.

The next section is the conclusion in this section I have written project conclusion.

After that I have done bibliography in this section write project references.

The last section is appendix in this section code 512-bit RSA algorithm in SAC and 64-bit of the RSA algorithm in C.

3.RSA Algorithm

3.1 Introduction:

The RSA algorithm is the most popular cryptography algorithm. RSA algorithm is developed in 1977 by a this three man named called Ron Rivest, Adi Shamir and Len Adlemen. It is published for the first time in 1978. This algorithm for public-key cryptography. The RSA name comes from the name of this three man Rivest-Shamir-Adeleman (RSA). This algorithm most commonly recognized and implemented a general-purpose methodology to public-key encryption (Stallings, 2011).

The RSA algorithm is very easy to understand. But calculation was very difficult and also time taking. In RSA algorithm public key and private key are based on large prime numbers. This algorithm was depended on mathematical fact.

3.2 Description of RSA algorithm:

The RSA algorithm is generally used in developing e-commerce and e-business system for the making digital signature and digital envelope (Doroeviae et al., 2002).Encryption is the process of converting plain text into cipher text. Assume a person A want to establish secure communication with person B using RSA algorithm. Person A and person B decide the value of n. Person A see the value of e and person B see the value of d. RSA algorithm Encryption and decryption are working on following equation.

C = Me mod N (encryption algorithm)

M = Cd mod N (decryption algorithm)

Now, see the above equation C it is called cipher text, and M it is called original Plain text. This equation e and n are mentioned public key of PU={e,n}, and d and n are mentioned private key of PB={d,n} (Stallings,2011).

3.2.1 Different step for Key generation of RSA algorithm

Here, summarizes the different step involve for RSA algorithm in key generation.

Step 1: Randomly select any of two large prime number p and q.

Step 2: Calculate value of n=p*q.

Step 3: Calculate the function φ (n)= (p-1)*(q-1).

Step 4: select any value of e, here value of e must be between 1 to φ(n).such that GCD(e, φ(n))=1.

Step 5: compute the value of d such that d*e =mod φ (n) .

(Sahu, 2011).

Below step are the encryption and decryption of RSA algorithm.

3.2.2 Encryption RSA algorithm

Step 1: Assume the person A want to send message to person B securely.

Step 2: Now, e has person B’s public key. Here e is public so A can access to e.

Step 3: This step encrypts the message M and represents a message on an integer in the range of 0<M<n.

Step 4: Here, equation cipher text C= Me mod n, here n is the modulus.

3.2.3 Decryption RSA algorithm

Step 1: Now, C has received cipher text from A.

Step 2: Compute message M= Ce mod n, here d is persion B of the private key and n is modulus (Dhakar et al., 2012).

3.3 Example of RSA algorithm:

First of all Choose 2 prime numbers.

p = 557, q = 821.

Calculate the modulus for the public/private key ‘n’.

Here, n is the number that is the same value in both keys, n =(p*q)= (7*17) =457297

Than Calculate the O of n.

O(n) = (p - 1) * (q - 1).

O(119) = (7 - 1) * (17 - 1). This equals 455920.

Now, we have got the these values:

p = 557

q = 821

n = 457297

O(n) = 455920

In this step Choose a value for e

This number is a bit harder than the others. This number has to be between 1 and n, it can also coprime to n. This basically means that the greatest common divisor of both numbers is 1. If you choose a prime number for e, so what you need to do now is check that e isn’t a divisor of n. Here, I have choose the number: e = 17

We will Calculating the modular multiplicative inverse of e * (mod O(n))

((e * x - 1) mod (O(n)) = 0) = 160913

Now, we can get all the value those we required in to implement algorithm Putting it all together

p = 557

q = 821

n = 457297

O(n) = 455920

e = 17

d = 160913

we are got the public-key is now: e = 17, n = 457297

Here, Private-key is now: d = 160913, n = 457297

Using this private and public-key data can be encrypted:

Here, encrypt the value 107

m = 107

Now, we will encrypt with the public key, take m to the power of e (in the public-key) mod n

m ^ e mod n

107 ^ 17 mod 457297 = 323453

Here, Our encrypted value is c = 323453

It can only be decrypted with the private-key. To decrypt it, you can take c to the power of d (in the private-key) mod n

c ^ d mod n

323453 ^ 160913 mod 457297 = 107 which is the decrypted value.

3.4 Security of the RSA algorithm

However, security is very important for the RSA algorithm. In RSA algorithm security and message encryption by the algorithm depends on the difficulty of factoring the value of n. If the value of n can be easily factored into the consistent value of p and q, At that time you can find valued easily. Suppose, Person A, B and C. Person A had sent messages to person B using public key encryption procedure EA. If person C want to see that message. They can be able to see that message in the ciphertext C=EA (M) format without the decryption key d. Person C can’t see the original message. The RSA algorithm security is described by following possible approaches to attacking the RSA algorithm (Kelly, 2009).

There are three approaches to attacking RSA algorithm.

Mathematical attacks:

Mathematical attacks are based on factoring the product of large primes. Such as factor n into its prime factors p and q respectively then computing φ, which has opportunity, enables determination of d = e-1 mod φ (Sharma et al., 2011).

Here, currently identified algorithms determining d given e and n look like to be at least as time consuming as the factoring problem. Now, we can use factoring performance as a benchmark compared to calculating the security of RSA (Stallings, 2011).

Timing attacks:

Implement cryptographic algorithm it is very important for execution on a non-constant time because of performance optimization. Timing attacks is if any one required another message it is very difficult for security of cryptographic algorithm. A timing attack idea is firstly purposed a cryptographic consultant Paul Kocher. They decide private key through track how long a computer task deciphers messages. Timing attacks are not a relevant only for the RSA but they other public key cryptographic system. This attack is only for two reasons, firstly it comes from an unexpected direction and secondly attacks only ciphertext (Stallings, 2011).

Chosen ciphertext attacks (CCA):

The RSA algorithm is at risk for a chosen ciphertext attack. Chosen ciphertext attack is a basically based on theoretical assumptions. Here, A public key cryptosystem is at risk for a Chosen Ciphertext attack, so frequently is measured to only a theoretical weakness. This attack needs more decryptions with every candidate key to identify the expected clear text data. The public key cryptosystem it does know the victim's public key, because an attacker can create own required clear text / cipher text pairs. The main problem an applying this method to the RSA algorithm is that all modular exponentiations is very costly, and its time complexity raises cubically with the size N of the modules (Salah et al., 2006).

4. Single Assignment C (SAC)

Single Assignment C (SAC) is a functional array processing language. SAC is supporting n-dimensional arrays as major data structure. A fact of SAC constitutes a no-frills functional variant of C. So, It has some benefits over commanding programming languages, like referential transparency. The all functional programming languages appear to be mostly apt for these demands. The absence of side special effects agrees complex code optimizations to be applied more simply since all data need to explicit. They allow the functional paradigm for an upper level of abstraction which commonly improves the overview of programs and so make simpler reuse and maintenance of existing programs. However, The programming languages dedicated to array processing powerful. A specifying array operation in an abstract manner has been developed. Starting out from a mathematical notation for arrays. Below basic design principles of SAC.

The first principle is call by value semantics.

In a SAC language is supported directly n-dimensional arrays.

Their support for shape-invariant array comprehensions.

SAC memory management is based on reference counting.

They have the aggressive high-level optimization to complete competitive runtimes (Grelck and Scholz, 2006).

SAC is designed to keep it closer to C language and on the other hand base it on the principle of context free substitutions. C Language attracts application programmers while SAC is designed for extensive compile time optimization as well as non-sequential execution. It uses reference counting techniques to overcome runtime and space efficiency whenever any single element of an array is modified, in other programming language any change in the element of an array needs to modify the entire array to be copied. This technique also helps programmers from the burden to think about memory issues entirely, as no memory needs to be allocated, arrays passed as arguments to functions can never be affected by such calls, and the programmer does not need to copy arrays in order to preserve a certain state. The programmer defines various arrays and relies on the compiler and the runtime system to ensure that the memory is being allocated and reused as often as possible (Scholz, 2003).

SAC supports shape invariant programming on the Meta level, it enables the programmer to design asset of shape-invariant operators to the particular requirements of a given set of applications. These operations can be stored within a library, which can be shared for the entire sets of application. An array on SAC represented by a two vectors, First one is a data vector in this vector all the elements in linear order and another one is shape vector they defines structural properties of the array (Scholz, 2003).

4.1 SAC Installation

If you want to do any program in any language it is necessary to install a language on your system. Below I am going to write about SAC available on following operating system.

Solaris (Sparc, x86)

Linux (x86 32bit, x86 64bit)

DEC (alpha),

Mac OS X (ppc. X86),

netBSD (under preparation).

SAC can install above five operating systems. SAC is currently not available on windows platform.

How to Compile and Run SAC program

To compile the SAC program, First of all we need save the file on right place, To save the file we will need to open a terminal windows and login as super user. After that open the right directory and then type sac2c<file_name>. sac . Now, Type command called ls we can see the three different file on our folder like a.out, a.out.c and <file_name>.sac . Last of all we can type command called a.out this file contains the results of our program (Scholz et al., 2010).

4.2 Basic Operation of SAC

In this section we are going to see about basic operation available on Single Assignment C (SAC).

genarray:

genarray function is used for a define a new array and they set a default value for a each element.

Syntax:

genarray ([dimension], <value>)

Example:

genarray ([1, 2, 3] ,2)

Now, we can see above example show the 3 dimensional array and set value of each element for a 2.

reshape:

The reshape function can be used for a reshape the parameter from an array.

Syntax:

reshape ([dimension], [array])

Example:

reshape ([2, 2],[1,2,3,4])

Here, we can see in the above example that is a 2 dimensional array and inner array can identical shape.

dim:

dim function shows the deimensity of the argument array.

shape:

Shape function is shown the vector argument an array.

rotate:

This function is used to rotate the array in leftmost axes and rightmost axes.

take:

They take certain element from an array.

drop:

They drop certain element from an array.

cat:

Cat returns the concatenation of two arrays.

4.3 SAC and C Comparison

In this section we are comparing SAC and C through one example programme. A program to find a minimum and maximum number from an array.

Find a minimum and maximum number in SAC

use StdIO: all;

use Array: all;

//A program to find maximum and minimum numbers from an array.

int main()

{

a=[1, 2, 0, 0, 4, 5, 6, 9, 9, 17]; // array

print(a); // print array

printf("Max is : \n");

print(maxval(a)); // print maximum number

printf("Min is : \n");

print(minval(a)); // print minimum number

return(0);

}

Here, Below figure 4.1 shows the output from above example in SAC.

Figure 4.1 Output of SAC Example

To implement a simple program in any language, it is necessary to first learn basic of that language and program. SAC is an array processing language. So I have implemented a simple array example program, a program to find a minimum and maximum number from an array.

In the simple program example. To implement the program, I have use following function. Firstly, I have defined an array from line 8. After that in line 10 prints an array. Line 13 finds maximum number of values in array and line 16 find the minimum number of values in array.

Now compile the program in SAC. Go to the terminal emulator and go to the same directory where the SAC program is saved. Then type the command:

Sac2c <program name>. Sac

Here, the program name is the file name in that I have written in SAC. After the completion of compiling programs generate a. out file. This file contains the output. So, type the command in a terminal window.

. /a. Out

Now figure 4.1 generates the output of the program. Here we can see that the dimension shows the array dimension i.e. 1D, 2D, 3D. Second is shape, show the number of elements in an array. Last we can see the result that shows the maximum number of array and minimum number of arrays.

Find a minimum and maximum number in C

#include <stdio.h>

// a program to find minumum and maximum from an array

void printarray(int a[], int length)

{

// A function to print array.

int i;

printf("\n");

for(i=0;i<length;i++)

printf("%d ",a[i]);

printf("\n");

}

int findmax(int a[],int length)

{

// A function to find maximum from an array

int i,res;

res=a[0];

for(i=1;i<length;i++)

{

if(res<a[i])

res=a[i];

}

return(res);

}

int findmin(int a[],int length)

{

// A function to find minimum from an array

int i,res;

res=a[0];

for(i=1;i<length;i++)

{

if(res>a[i])

res=a[i];

}

return(res);

}

void main()

{

int a[10]={1, 2, 0, 0, 4, 5, 6, 9, 9, 17}; // Define Array

printarray(a,10); // Print Array

printf("\nMax Value is : %d ",findmax(a,10)); // Print Maximum Number

printf("\nMin Value is : %d",findmin(a,10)); // Print Minimum Number

printf("\n");

}

Here, Below figure 4.2 shows the output from above example in C.

Figure 4.2 Output of C example

In comparing to SAC and C it is necessary to implement the same program in C. So I have implemented the same program in C.

An example shows the find a maximum and minimum number from an array in C. In C language I have used four functions in coding. Firstly, I have used void printarray () this function can use print array. Secondly, void findmax () this function was written to find the maximum value from an array. After that void findmin () this function can be used to find the minimum number from an array. Then the last function void main (), In this function array is defined, print the array, print a maximum and minimum number from an array.

After we need to compile this program, open terminal emulator and go to the directory then type a command:

gcc <filename>. c

Here, the file name is written the file name of the program. Same here gcc compiler generates the one file called a. out. These files contain the output of the program. So we need to run that file type command on terminal emulator.

. /a. Out

Figure 4.2 shows, The output of above example . Here, See the first row shows number of elements available from an array. Next, generate Output and print maximum number from an array. Last they print the minimum number from an array.

4.4 Difference and Similarity of SAC and C

In this section we are going to see what a similarity between SAC and C is and what the difference between SAC and C.

SAC and C similarity we have seen above example. The programming syntax is same in a SAC and C language. As well as they generate same output from programs. In at both languages all the line ended with ; (semi-columns). If we can do the coding in SAC or C language they must require main function. Another similarity was if you want to comment the one line or more than one line we can use // or /*…….*/. In both languages use of function In the same like if .… else, while, for etc. that’s the similarity of SAC and C.

Now, we are discussing about what is a difference between SAC and C. The first difference is we have seen in the example program number of line code only 13 lines in SAC and other side in C language 39 line of code. We are not considering blank line and commented line in both languages. Secondly, the SAC have inbuilt function called print () this function print the array dynamically. In C language we have created a user defined function. Another difference is SAC has memory allocation is dynamically to the array. Other side C has if we are using a pointer, so we have to allocate memory to the pointer.

5. Measurement and Performance Testing

Measurements are very important if you are producing software algorithm. Measurement through we can control, evaluate and improve the process of software.

To define measurement According to Lord Kelvin (1924-1904) "when you can measure what you are speaking about and express it in number, you know something about it. Otherwise your knowledge is a meagre and unsatisfactory kind; it may be the beginning of knowledge but you have scarcely in thought advanced to the stage of science" (Lim and Ahmed, 2000).

To do measurement there are many measurement techniques available like LOC, Function point, Time complexity, etc. Here, We are used to measure RSA algorithm LOC and Time complexity techniques.

5.1 LOC (Line Of Code)

LOC stands for a Line Of Code. The LOC is used to measure the size of software and algorithm. The LOC is another way to write KLOC. LOC is a very easy technique. We have here used LOC technique and measure the size of RSA algorithm.

LOC can be measured in three ways, Firstly kLOC (k=1000) means a 1000 line of code. kLOC can count the all the line including commented line of code. Second one is a NCLOC (Non Comment Line Of Code) can be counted only the non-commented line of code. Lastly, CLOC (Comment Line Of Code) is counted only comment line of code. We can take a simple example of a C program.

#include <stdio.h>

//#include <conio.h>

int main( int m, char *argv[] )

{

printf( "how are you.\n" );

return( 0 );

}

Now we can measurement of above example with LOC technique LOC=7 , NCLOC=6 and CLOC=1.

Below Table 5.1 shows the measured size of implementing the RSA algorithm thought LOC technique.

CODE

LOC

NCLOC

CLOC

512-Bit RSA in SAC

550

534

16

64-Bit RSA in C

151

144

07

Table 5.1 Measurement size of RSA algorithm SAC and C

Table 5.1 shows the measured size of the RSA algorithm in SAC and C. Here, column 1 is a code written in a SAC and C. Column 2 is represents the Line Of Code. Column 3 represents Non-Comment Line Of Code and last column represent the Comment Line Of Code. Normally this measurement technique can be used on a big project.

5.2 Time complexity

Time complexity is a very important measurement for a this algorithm. Complexity can be expressed use of big-O notation. The time complexity is generally estimated by counting the number of fundamental operations performed by the algorithm. Here, A fundamental operation takes a fixed amount of time to get output. A computer can perform different operations in deferment speeds. Some system have addition is very fast and other side division is very slow. The system can also be differ in size and processor, memory and disk speeds. The time complexity has most interesting property of an algorithm.

We can measure the RSA algorithm using time command. We are going to measure this way the time complexity of execution of algorithm. For Measure time we can use of command time available on Linux. Write a command in command window

$>time<command>.

The time command is given the output is real time,user time and sys time(system time). They give you a how much CPU time used by your process and how much CPU time used by the system by behalf of you. This command is not use for a system time. This command is for a only a specific task how long they task.

Below Table 5.2 shows the performance of RSA algorithm key generation Time in second.

Key Size ( Bit )

Key Generation Time ( Sec )

32

0.007

64

0.118

128

2.002

256

22.358

512

420.455

Table 5.2 performance of RSA algorithm Key generation time

Table 5.2 is a performance of RSA algorithm key generation. Here, first column shows the key size in a number of Bit and the second column shows a key generation time in a second.

Now, we can describe all the given data using line graphs.

Below figure 5.1 shows the chart of an RSA algorithm key generation time.

Figure 5.1 Performance chart of RSA key generation

Above figure 5.1 shows the key generation time of RSA algorithm. Here, X-Axis represents the data size in a number of bit and Y-Axis is a Time of key generation in a second. Here , we can see on a graph data size 32-bit to 128-bit key generation time has slightly increased. After that 128-bit to 256-bit is a increased almost 10 times by 128-bit. Lastly , data size is 256-bit to 512-bit time was suddenly rise time is 420.255 second.Table 5.3 shows the performance of RSA algorithm with 32-bit key size in SAC.

Data Size (Bit)

Encryption Time (Sec)

Decryption Time (Sec)

32

0.014

0.067

64

0.021

0.168

128

0.042

0.257

256

0.082

0.512

512

0.155

1.033

1024

0.292

2.057

Table 5.3 Performance testing of RSA 32-bit key size

Above table 5.3 column 1 is a data size in bits, column 2 represents a Encryption time in a second and last column is a Decryption time in a second.

Below figure 5.2 chart shows the RSA 32-bit key size comparison of encryption and decryption time.

Figure 5.2 performance chart of RSA 32-bit key size

Above figure 5.2, X-Axis represents data size in a number of bit and Y-Axis represents time in a second. First of all see the encryption time is starting to end increases gradually as we increase data size. But in a other side decryption time is increases sharply as we increase data size.

Table 5.4shows the performance of RSA algorithm with 64-bit key size in SAC.

Data Size (Bit)

Encryption Time (Sec)

Decryption Time(sec)

128

0.025

0.232

256

0.048

0.436

512

0.095

1.125

1024

0.165

1.87

2048

0.34

3.644

4096

0.679

7.454

Table 5.4 Performance testing of RSA 64-bit key size

Above table 5.4 column 1 is a data size in bits, column 2 represents a Encryption time in a second and last column is a Decryption time in a second.

Below, figure 5.3 is shows performance chart of RSA 64-bit key size.

Figure 5.3 performance chart of RSA 64-bit key size

Figure 5.3 shows a comparison chart of encryption and decryption time of RSA 64-bit key size. Here, X-Axis represents the data size in a number of bit and Y-Axis represents time in a second. We can say that here encryption time is 128-bit to 4096-bit increase very slowly. Other side decryption time is increases regularly as we increases data size.

Table 5.5 shows the performance of RSA algorithm with 128-bit key size in SAC.

Data Size (Bit)

Encryption Time (Sec)

Decryption Time (Sec)

128

0.088

1.611

256

0.13

3.298

512

0.265

7.581

1024

0.518

13.378

2048

1.034

27.458

4096

2.005

52.346

Table 5.5 Performance testing of RSA 128-bit key size

Table 5.5 is a performance of RSA algorithm 128-bit column 1 is represent the data size in number of bit column 2 represent encryption time in a second and column 3 represent decryption time in a second.

Figure 5.4 chart shows the performance of RSA algorithm of 128-bit key size.

Figure 5.4 performance chart of RSA 128-bit key size

Above figure 5.4 chart show the performance of RSA algorithm with 128-bit key size. Here, X-Axis represents the data size and Y-Axis represent time. We can say that encryption time is increasing gradually and decryption time is increased step by step.

Table 5.6 shows the performance of RSA algorithm with 256-bit key size in SAC.

Data Size (Bit)

Encryption Time (Sec)

Decryption Time (Sec)

128

0.193

10.035

256

0.371

20.248

512

0.732

40.26

1024

1.457

80.546

2048

2.804

160.211

4096

5.547

318.533

Table 5.6 Performance testing of RSA 256-bit key size

Above table 5.6 shows data of RSA algorithm with 256-bit key size. The first column represents the data size. Second and third column represents the encryption and decryption time respectively.

Figure 5.5 shows the comparison chart of RSA algorithm with 256-bit key size.

Figure 5.5 performance chart of RSA 256-bit key size

Figure 5.5 shows the comparison of encryption and decryption time of RSA algorithm. Here, X-Axis represents the data size and Y-Axis represent the time. In this chart encryption time is increasing sharply to the 128-bit to 4096-bit. The decryption time increasing ratio is almost double if we use 128-bit data size then takes time is 10.035 and if we use 256-bit data size than take time is 20.248 if we increase data size.

Table 5.7 shows the performance of RSA algorithm with 512-bit key size in SAC.

Data Size (Bit)

Encryption Time (Sec)

Decryption Time (Sec)

256

1.253

133.648

512

2.434

265.678

1024

3.615

397.708

2048

4.796

529.738

4096

5.977

661.768

Table 5.7 Performance testing of RSA 512-bit key size

Above table 5.7 shows the performance of RSA algorithm with 512-bit key. In table 5.7 column 1 represents the data size in a bit. Column 2 and column 3 represents the Encryption and decryption time in a second respectively.

Figure 5.6 shows the comparison chart of RSA algorithm with 512-bit key size.

Figure 5.6 performance chart of RSA 512-bit key size

Figure 5.6 shows the comparison of encryption and decryption time of RSA algorithm with 512-bit key. X-Axis represents the data size and Y-Axis represent the time. However, encryption time is increased step by step. On the other side decryption is suddenly rise as we increase data size.

We have seen above all the chart figure 5.2, 5.3, 5.4, 5.5 and 5.6 so we can say that, if we increase the data size or key size then increase time of encryption and decryption.

6. Discussion

In this section we are going to discuss about implemented RSA algorithm in SAC and C. First of all discuss about 512-bit RSA algorithm in SAC. Then after discuss about 64-bit RSA algorithm in C using long long data type.

6.1 512-bit RSA algorithm in SAC

How we can implement RSA algorithm with 512 Bit key size?

It is very easy to implement RSA algorithm with 32 bit key size and 64 bit key size. We can implement this algorithm with short key size in C and in SAC also by using arithmetic operation such as mod, power, etc.

To achieve the result for 512 bit RSA algorithm, we have think differently, because if we use int or long long int, they support only 32 bit and 64 bit respectively. To solve this problem, we have to implement functions that can support more than 64 bits.

To implement functions that supports more than 64 bits, we have to take our data type in binary array. Each element of an array represents bit 0 or 1. E.g. Message = [1,0,1,0,0,0,1]. Here in this example message size is 7 bit and message is 81.

In RSA, most important functions are ency=me mod n and decy=encyd mod n. It is very easy to implement these functions with decimal arithmetic. We can perform these operations with fewer steps. But, if we want to implement these functions in binary data type, we have to implement different functions, because there are no supporting library that supports binary operation.

How we can implement the binary arithmetic?

To do arithmetic in binary, we have to implement some functions such as binary addition, binary subtraction, binary multiplication, etc.

In this project I have implemented some functions that perform binary addition. We will discuss basic logic to implement these functions one by one by taking an example.

Binary addition:

Suppose we have two array of binary a=[1,0,0,1] and b=[1,0,1,1] . Now we want c= a+ b.

We have to take both arrays in reverse order. E.g. last bit comes first and first bit comes last. For bit to bit we have to do addition. Rules for the addition are:

1 + 1 = 0 and Parity = 1

1 + 0 = 0 and parity = 0

1 + 1 + 1 = 1 and parity = 1

Steps / bit position (i)

A[i]

B[i]

parity

C[i]=a[i]+b[i]+parity

3

1

1

0

0

2

0

1

1

0

1

0

0

1

1

0

1

1

0

0

Final result

A=

B=

1

C=101000

Table 6.1 Binary addition

Binary Subtraction:

Suppose we have two arrays. A = [ 1,0,1,1], B= [1,0,0,1] and C=A-B.

To, do substation of binary arrays, we have to calculate 2’s complement of 2nd array. Then do the binary addition with 1st array. Keep in mind; we have to ignore final parity.

How to do 2’s complement?

Take the array in reverse order.

Take the same bit until finding 1st occurrence of bit 1.

For rest of all bits do,

1 = 0

0 = 1

2’s complement of array B= [1,0,0,1] is [0,1,1,1].

Steps / bit position (i)

A[i]

2’scomplementB[i]

parity

C[i]=a[i]+ 2’scomplementB [i]+parity

3

1

1

0

0

2

1

1

1

1

1

0

1

1

0

0

1

0

1

0

Final result

A=

B=

1

C=0010

Table 6.2 Binary Subtraction

Binary multiplication

To multiple binary, this function can be used. In this session we will discuss the logic behind this function.

Suppose we have two binary numbers, A= [1,0,0,1], B= [1,0,1,1] and C= A * B. To obtain a result we have to go through the following steps.

Take an array result = 0

P=0

i= (length (b) – 1) to i=0

if b[i]==1

take pre = result

result=embed (p) times 0 in a

result= binary addition of pre and result

p=p+1

i = i-1

Return result

Step(i)

B[i]

Pre=result

Result=a+ (embedding zeros)

Result=pre+result

P

3

1

0

1001

1001

0

2

1

1001

10010

11011

1

1

0

2

0

1

11011

1001000

1100011

3

Final Result=

1100011

Table 6.3 Binary multiplication

Binary division

Binary division is a function, can be used for division. Suppose we have two array A=[1,1,1] and B=[1,1] and C=A/B. To perform this task we have to go through the following steps. Not that this function accepts two argument a and b.

Res=0

Len=length (a)

Lenb=length (b)

Resdiv=0

For i=0 to i<len

Res = add a[i] after res

Remove leading zeros from res

Lenres=length (res)

If (lenres<lenb)

Resdiv=add 0 after resdiv

If (lenres=lenb)

If res > b

Res = res – b

Resdiv =add 1 after resdiv

Remove leading zero from res

Else

Resdiv = add 0 after resdiv

Else

Res = res – b

Remove leading zero from res

Resdiv = add 1 after resdiv

i=i+1

return resdiv

Steps (i)

A[i]

Res

Length(res)

Resdiv

B

Res

0

1

1

1

0

11

1

1

1

11

2

01

11

-

2

1

1

1

010

11

-

Final Result=

10

Table 6.4 Binary division

Binary modulus

This function is used to find Modulus of two binary numbers. This function is very important for this project. Suppose we have two array A=[1,1,1] and B=[1,0] and C=A(modB). The logical steps are listed below. Keep in mind that this function is recursive and accepts two parameters a and b containing binary array.

Lena=length(a)

Lenb=length(b)

Res=0

If lena<lenb

Res=a

If lena=lenb

If a<b

Res=a

Else

Res=a-b

If lena>lenb

Div=takes elements from a.( no of element=length(b))

If div < b

Div=div + append one next element from a

Div=div-b

Div=div + append remaining elements from a

Res= go to step 1

Else

Div = div –b

Div =div + append remaining elements from a

Res=go to step 1

Return res

A

B

Lena

Lenb

Div

Div=div-b

res

Div=div+elements from a

111

10

3

2

11

1

11

11

10

2

2

1

Final Result=

1

Table 6.5 Binary modulus

Now, we will discuss implementation of RSA algorithm with 512 bit key size. In below Table 6.6 we will discuss how we have implemented this algorithm in SAC with all functions. In Table 6.6, there are several functions mentioned, are used to implement RSA algorithm

Function name

Return type

Parameters

Binadd

Int,int

Int a, int b, int c

Binary_mult

Int[.]

Int[.] a, int[.] b

Binary_mod_power

Int[.]

Int[.] a,int[.] b and int[.] c

Int2bin

Int[.]

Int a

Key256bit

Int[.]

Int keysize

Ckeckprime

Int

Int[.] p

Binary_candidate

Int[.]

Int[.] n

Binary_div

Int[.]

Int[.] a,int[.] b

Hex2bin2

Int[*]

Int a

Hex2bin3

Int[*]

Int [.] a

Hex2bin

Int[*]

String s

Bin2hex

Char

Int[.] a

Hexdisplay

Void

Int[.] a

Reshapearray

Int[.,.]

Int[.] a,int n

Main

Int

-

Table 6.6 Function used implements RSA algorithm in SAC

Note: Table 6.6 [.] – represents a 1D array, [.,.]and [*] represents 2D array.

Now, we will discuss all these functions in details.

Binadd

This function accepts three parameters: a,b and c, all parameters are in INT.

This function returns two variables in INT format. One is res and another is carry.

First it sums a,b and c.

Checks the result=a+b+c.

If result=0 then res=0 and carry=0

If result=1 then res=1 and carry=0

If result=2 then res=0 and carry=1

If result=3 then res=1 and carry=1

This function is used while doing addition of two binary.

Binary_addition

This function accepts two parameters: a and b: both are in int[.].

This function returns one variable in int[.] format, named res.

This function is used to do addition of two binary array a and b.

In this function binadd function is used.

Twoscomp

This function accepts one variable :a in int[.]

This function returns a variable in int[.] format named a..

This function is used to do 2’s complement of binary variable a.

This function can be used while doing binary subtraction.

Binary_sub

This function accepts two parameters : a and b, both are in int[.].

This function returns one variable in int[.] fromat, named res.

This function is used to do binary subtraction of two binary variable a and b.

This function, two’s complement and binary addition function are used.

Positionone

This function accepts one parameter : a in int[.]

This function returns one variable in int named res.

This function is used to find the first occurrence of 1 in given array a.

Binary_max

This function accepts two parameters : a and b, both are in int[.].

This function returns one variable in int named res.

This function is used to determine which binary number is greater than other.

This function returns 1 if a>b else returns 0.

Binary_mod

This function accepts two parameters: a and b, both are in int[.]

This function returns one variable array int[.] named res.

This function is used to calculate modulus of array a. e.g. a mod b.

Binary_mult

This function accepts two parameters: a and b, both are in int[.].

This functions returns one variable array int[.] named result.

This function is used to calculate multiplication of two binary a and b. e.g. a X b.

Binary_mod_power

This function accepts three parameters: a, b and c. each of them is int.

This function returns one variable array in int[.] named finalres.

This function is used to calculate exponential modulus of a. e.g. ac mod b.

Int2bin

This function accepts one parameters a in int.

This function returns one variable array in int[.] named res.

This function is used to convert a decimal number into binary.

Key256bit

This function accepts one parameters keysize in int.

This function returns one variable array in int[.] named p.

This function is used to generate up to 256 bit prime number.

Checkprime

This function accepts one parameters p in int.

This function returns a variable int named prime.

This function is used to determine whether p is prime or not.

It returns 1 if p is prime else returns 0.

Binary_candidate

This function accepts one argument n in int[.].

This function returns a variable int[.] named res.

This function is in key generating process.

This function is used to calculate private exponential (d) in RSA.

Binary_div

This function accepts two arguments a and b; both are in int[.].

This function returns a variable array in int[.] named resdiv.

This function is used to calculate the division of two binary numbers. E.g. a/b.

Hex2bin2

This function accepts one argument a in int.

This function returns variable a in int.

This function is used to convert a ASCII into HEX value.

Hex2bin3

This function accepts one argument a in int[.]

This function returns a variable array int[*] named res.

This function is used to convert HEX value into binary equivalent.

Hex2bin

This function accepts one argument s in string.

This function returns a variable array int[*] named intsb.

This function is used to convert string into hex binary.

Hexdisplay

This function accepts one argument a in int[.].

This function is a void and has no return type.

This function is used to display HEX data.

Reshapearray

This function accepts two argument a in int[.] and n in int.

This function returns one variable in int[.,.] named mreshape.

This function is used to reshape an array a into 2D array.

How does program work?

This program is written in SAC. There are four main steps of this program.

Figure 6.1 How programme work

Generate P and Q

Key256bit

Generate random number p

Is P prime ?

Returns P

End

Yes

No

Figure 6.2 Algorithm Generate P and Q

Calculate n, e and on

Start

N= p X q

E= [ 1 0 0 0 1 ]

On=(p-1) X (q-1)

End

Key256bit

Figure 6.3 Algorithm calculate n,e and on

Calculate private exponential d.

Binary_candidate

I=1

B= n X i

B= b +1

Res = b % 17

Is Res=0?

Res = b / 17

Return res

I = I +1

Figure 6.4 Algorithm Calculate private exponential d

Encryption and decryption

Start

Convert Text into block

M=next block bits

Ency=binary_mod_power(m,n,e)

Next Block?

End

Figure 6.5 Algorithm Encryption and decryption

6.2 64-bit RSA algorithm in C

This section we can discuss about 64-bit RSA algorithm in C using long long data type. Long long data type can be used to handle very large number in C language. Basically, in C language number of 32-bits can’t exceed a specific value, So in order to handle a specific value handling 64-bit integers in C programing language. To print a long long data type display is different from other data types. The long long data type makes handling 64-bit integers easy.

Now, we can start with a declaration of the header file and use of this file. First is #include <stdio.h> this file is very important in C language. If you are doing any program in C language you need to import first this file. Use of this file is input and output of function. After that I have import #include<stdlib.h> this file is called standard library. It is describing a several operation functions like allocate memory, conversation and process control. Next, is #include<ctype.h> it is used for declaration character function, testing and converting characters. Then include<math. h> this file is used for various mathematical operations like returns log of the number or returns a square root of number and many more. After that include<time. h> this file is provided the various functions used reading and converting current date and time. Last one is an include<string. h> this header file is include declaration, function and constraints of string handling and also provide many functions used for manipulating strings.

The long getrand method can create the series of random numbers and get a random number. isPrime function is used for a check given number is prime or not. If the number is divisible for only one and itself then generating number as a prime number.

Now , we will discuss how we have implemented this algorithm, we have to implement some functions which are not inbuilt in C. Below in table 6.7; I have mentioned functions used to implement this algorithm.

Function Name

Return Type

Parameters

Getrand

Long

Long toprange

Isprime

Int

Long num

Generateprime

Void

Candidates

Long long

Long long qn, int e

toBinary

Void

Long long a, char *c

Expmod

Long long

Long long a, char *e, long long n

Main

Int

Table 6.7 List of function implement RSA algorithm in C

We will discuss above listed all functions in details.

Getrand

This function accepts one parameter toprange in long format.

This function returns a variable of long type.

This function is useful in generating randomize numbers.

isPrime

this function accepts one parameter num in long format.

This function returns a variable of int type.

This function is used whether input number is prime or not.

This function returns 1 if num is prime else returns 0.

Generateprime

This function does not accept any parameter.

This function has type of void, so it has no return variable.

This function is used to generate prime and stores the values of p and q.

Candidates

This function accepts two variable qn and e have data type long long and int respectively.

This function returns a variable of type long long.

This function is used to calculate private exponential (d).

toBinay

This function accepts two variable long long a and char *c.

This function is a type of void hence it has no return value.

This function Is used to convert a into binary and stors value in c.

Expmod

This function accepts three variable long long a, char *e and long long n.

This function returns a value in the long long format.

This function is used to calculate encryption and decryption. E.g. Me(mon n).

Conclusion

In this project we have implemented the RSA algorithm in SAC as well as in C. C is a basic programming language and has accepted widely in the world and is the most popular language. On the other hand SAC is still in research and is not commercially accepted in the world. So, basically, SAC takes time to learn and SAC is also derived from C.

In terms of performance, C takes a less time than SAC to compile, because, when we compile the SAC file, it creates a C file and compile it.

In terms of Memory Management, SAC is better than C. C does not provide dynamic memory on run time, while SAC provides dynamic memory on runtime. In C, once you have allocated memory, you cannot change memory, while in SAC, you can do this.

So, for this kind of algorithms like RSA, etc., SAC is the better option than C.

Bibliography



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now