Question: USE OCTAVE ONLY You should implement such an encryption/decryption program but with some additional customizations (please refer to the hints too). You can implement your

  1. USE OCTAVE ONLY You should implement such an encryption/decryption program but with some additional customizations (please refer to the hints too). You can implement your program using the phases given below:
    1. [25 pnts] Write a function for doing the encryption, it will have this definition:

2. function encStr = encrypt(s,key)

    1. [20 pnts] Write a function for doing the decryption, it will have this definition:

4. function dcrpt = decrypt(encStr,key)

    1. [15 pnts] Write a main program which will:
  • Input an original message and a key (hint: the message must be entered in

between single quotes)

  • Call the encryption function to encrypt the message and display the result
  • Call the decryption function to decrypt the encrypted message and display

the result

  • Compare between the original message and the decrypted message and

display true or false according to the result

    1. [20 pnts] Edit your code (main, encrypt, decrypt) to include the following case: if there are spaces in the original message, the output message should have spaces also in the same locations ; for example:
  • Original message: abc de , key=3
  • Output message: def gh

Therefore, you should find the indices of the spaces (indxSp) in the original message and return them from the encryption function in order to use them in the decryption function, so the definition will be:

function [encStr,indxSp]=encrypt(input,key)

function dcrpt=decrypt(encStr,key,indxSp)

5. [20 pnts] Edit your code (main, encrypt, decrypt) to include the following case: If there are capital letters in the original message, the output message should be in small letters (all the letters are small) but you should keep the indexes of the capital letters in order to use them in decryption; the decrypted message should be the same as the original (sensitive comparison); for example:

  • Original message: Abc De , key=3
  • Output message: def gh
  • Decrypted message: Abc De

Therefore, you should find the indexes of the capital letters (IndxC) in the original message and return them from the encryption function in order to use them in the decryption function, so the definition will be:

function [encStr,indxSp,indxC]=encrypt(input,key)

function dcrpt=decrypt(encStr,key,indxSp,indxC)

Hints:

  • In octave: o a= abc

o char(a+3) will give you : def

  • The space is implemented in the computer as a number equal to 32 (called

ASCII code), so in octave: char(32) is the space

  • Refer to the functions which mentioned in the lecture: isspace(), lower(),

upper(),strcmp(s1,s2) , isstrprop( s, 'property' )

  • To find the indexes of 1s in an array, use the function: find(x) which returns a

vector containing the indexes of each nonzero element in array X. Example:

o x=[1 0 1 0]

o find(x) will give you: [1 3]

  • To check if there are a capital letter in an input, use isstrprop(input,'upper')

Example: o input=AbC o isstrprop(input,'upper') will give you: [1 0 1]

  • In octave: o a=[1 0 1]

o sum(a)>=1 will give you 1

Some output examples: (after implementing all of the five questions)

>> main Enter message to be encrypted:'hello world' Enter the key:2 The encrypted message is: jgnnq yqtnf The decrypted message is: hello world The comparison result is: True

>> main Enter message to be encrypted:'Hello World' Enter the key:2 The encrypted message is: jgnnq yqtnf The decrypted message is: Hello World The comparison result is: true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!