Starting from:
$35

$29

Programming Assignment 3 Solution

The science of writing secret codes is called cryptography. For thousands of years cryptography has made secret messages that only the sender and recipient could read, even if someone captured the messenger and read the coded message. A secret code system is called a cipher.




In cryptography, we call the message that we want to be secret the plaintext. The plaintext could look like this:




Hello there! The keys to the house are hidden under the flower pot.







Converting the plaintext into the encoded message is called encrypting the plaintext. The plaintext is encrypted into the ciphertext.




The ciphertext looks like random letters, and we cannot understand what the original plaintext was just by looking at the ciphertext.




Here is the previous example encrypted into ciphertext:







Yvccf kyviv! Kyv bvpj kf kyv yfljv riv yzuuve leuvi kyv wcfnvi gfk.







But if you know about the cipher used to encrypt the message, you can decrypt the ciphertext back to the plaintext. (Decryption is the opposite of encryption.)



















Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 1

CS 4350 – Unix Systems Programming







Many ciphers also use keys. Keys are secret values that let you decrypt ciphertext that was encrypted using a specific cipher.




Think of the cipher as being like a door lock. You can only unlock it with a particular key.
















encrypt a message by taking each letter in the message (in cryptography, these letters are called symbols because they can be letters ( A-Z) ( a-z ), numbers( 0-9 ) , all symbols and replacing it with a “shifted” letter.




Using letters are , If you shift the letter A by one space, you get the letter B. If you shift the letter A by two spaces, you get the letter C. For example , this is a picture of some letters shifted over by three spaces.







































































































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 2

CS 4350 – Unix Systems Programming














































The number of spaces you shift is the key in the Cipher. The example above shows the letter translations for the key 3.




If you encrypt the plaintext “Howdy” with a key of 3, then:













The “H” becomes “K”.



The letter “o” becomes “r”.
The letter “w” becomes “z”.
The letter “d” becomes “g”.
The letter “y” becomes “b”.












The ciphertext of “Howdy” with key 3 becomes “Krzgb”.


















































































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 3

CS 4350 – Unix Systems Programming
















We will keep any non-letter characters the same. To decrypt “Krzgb” with the key 3, we go from the bottom boxes back to the top:













The letter “K” becomes “H”.



The letter “r” becomes “o”.



The letter “z” becomes “w”.



The letter “g” becomes “d”.



The letter “b” becomes “y”.





















































































































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 4

CS 4350 – Unix Systems Programming







You will write a C program that accept a message and the word encrypt , decrypt , or exit ( not case sensitive ) . The program then will do the following :




Encrypt a message – Enter a key and :






Count and display number of capital letters , Small letters , digits and symbols in the message.



Count number of characters in the message.



Convert all small characters to capital letters and vice versa the display the message.
Encrypt the original message



Concatenate the encrypted message with the original message






Decrypt a message – Enter a key and :






Count and display number of capital letters , Small letters , digits and symbols in the message.
Count number of characters in the message.



Convert all small characters to capital letters and vice versa then Display the message.



Decrypt the original message.



Concatenate the decrypted message with the original message



Exit the program. Terminate the program.






Anything is incorrect.






















Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 5

CS 4350 – Unix Systems Programming



















Guideline:







Must use 2 dimensional array



key number must be between 1 and 93. Anything else should be rejected.



Must have one function for populating the 2d array and encrypting the message and all other functions.



Must have one function for populating the 2d array and perform the decrypting the message and all other functions.



Must pass parameters ( message and the key ) to encrypt or decrypt functions .



Must have one function to perform the validation ( encrypt , decrypt , exit and the key number ).



You are not allowed to use the functions that are provided by C libraries when writing this program.



















































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 6

CS 4350 – Unix Systems Programming







Your encryption / decryption arrays will contain the following characters and numbers in the that sequence.












A – Z followed by







a -­ z followed by







0 -­ 9 followed by the following symbols in







(exclamation mark) " (Quotation mark)



# (Number sign) $ (Dollar sign) % (Percent sign)




(Ampersand)



(Apostrophe)



(round brackets or parentheses) ) (round brackets or parentheses) * (Asterisk)



+ (Plus sign)




(Comma)



-­‐ (Hyphen)
















(Full stop, dot)









Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 7

CS 4350 – Unix Systems Programming







(Slash) : (Colon)
(Semicolon)



(Less-­than sign) = (Equals sign)



(Greater-­than sign; Inequality) ? (Question mark)




@ (At sign)




[ (square brackets or box brackets)




\ (Backslash)




(square brackets or box brackets) ^ (Caret or circumflex accent)
_ (underscore, understrike, underbar or lowline) ` (Grave accent)

{ (curly brackets or braces)




-­ (vertical bar, vbar, vertical line or vertical slash)







} (curly brackets or braces) ~ (Tilde; swung dash)





























































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 8

CS 4350 – Unix Systems Programming







9 ) Must place the following information on top left of the first page of your assignment as comments










NAME : ______________________ CS 4350 – Unix Systems Programming







Serial Number:




Group Number:




Assignment Number: ___________




Due Date: 3 / 27 / 2019










Sample Run







Welcome to cryptography







What would you like to do to a message? ( encrypt , decrypt, exit )




Enter your choice : nothing




Invalid message







What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : exit







and YYYYYYY Security Systems 3-­‐27-­‐2019













































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 9

CS 4350 – Unix Systems Programming







Sample Run







Welcome to cryptography







What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : encrypt







Enter your message:




HG




Enter the key number (1-­‐93)




100







Invalid Key Number







What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : exit













and YYYYYYY Security Systems 2-­‐27-­‐2019




















































































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 10

CS 4350 – Unix Systems Programming







Sample Run







Welcome to cryptography







What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : encrypt







Enter your message:




HG




Enter the key number (1-­‐93)




3







Number of Capital Letters: 2




Number of Small Letters: 0




Number of Digits : 0




Number of Symbols : 0




Number of Characters in the message : 2




Converting Letters : hg




The decrypted text is:




KJ




Concatenation of original and encrypted text : HGKJ










What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : exit







and YYYYYYY Security Systems 3-­‐27-­‐2019




































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 11

CS 4350 – Unix Systems Programming













Sample Run







Welcome to cryptography







What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : decrypt




Enter the key number (1-­‐93)




3




Enter your message:




VWDWH







Number of Capital Letters: 5




Number of Small Letters: 0




Number of Digits : 0




Number of Symbols : 0




Number of Characters in the message : 5




Converting Letters : vwdwh







Your encrypted text is:




STATE







Concatenation of original and encrypted text : VWDWHSTATE













What would you like to do to a message? ( encrypt , decrypt, exit ) Enter your choice : exit







and YYYYYYY Security Systems 3-­‐27-­‐2019



























Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 12

CS 4350 – Unix Systems Programming







Instructions :




Can work as a group of 2.
Must submit one file that contains all your source code.
The output must follow the sample run format.
You must upload your solution using TRACS – Make sure you include the above as comments in



your program




Make sure that you name your homework document as follows :




HW3_CS4350_LastName_FirstName.c







Where LastName is your Last Name and FirstName is your First Name. For example , the file name should look something like :




You must upload your programs no later than the starting of class time on the due date.

Everyone must upload the electronic version. No late assignments will be accepted..







You must also turn in hard copy of your source code no later than the due date / time

Please turn one hard copy / group . Should the hard copy consist of more than one page , then , the hard copy must be stapled. if you are unable to turn in a printout during class, you can take the program to the computer science department and hand it to the front desk personal (Comal 211 ) before the deadline. Make sure that the front office stamps the program. Make sure that include the date and time. Finally ,make sure that they place the program in my mailbox. No late assignments will be accepted..



DO NOT slide your program under my office door – It will NOT be accepted



































































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 13

CS 4350 – Unix Systems Programming







The following points will be deducted if :










Compilation Errors, missing electronic copy , missing the hardcopy , not



written in c programming language, submitting .zip file, submitting files other than .c or .txt file, using functions such as strlen , isdigit … etc




( - 10 points )




• Logical Errors ( at least 1 points )




• Other ( at least 1 points ) if any of the following takes a place :




Unable to read the source code due to unclear printing



Incorrect Output format.



Incorrect program file name.



Hard copy is not stapled.



More than one hard copy per group.



Incorrect Style such as but not limited to Missing Header comments, missing footer comments, not replacing my name with your name, missing serial number , missing section number … etc.



Not using at least functions and not passing parameters to functions … etc


























































































Spring 2019 – Husain Gholoom – Lecturer in Computer Science Page 14

More products