You are on page 1of 4

CIS 3360 Program #1: Hill Cipher

In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Hill cipher. Your program should prompt the user for the names of two input files and one output file:

1) The file storing the encryption key ) The file to be encrypted !) The corresponding encrypted file

Your program should open the first two files" make the necessary calculations and write the cipherte#t to the third file.

If the file to be encrypted doesn't ha$e the proper number of alphabetic characters" pad the last block as necessary with the letter '%'.

Encryption Key File Format The encryption key file will store a single positi$e integer" n (1 < n < 10)" on the first line" indicating the number of rows and columns in the encryption matri#. The following n lines will contain the contents of each row" in order" of the encryption matri#" separated by spaces.

Format of the File to be Encrypte The file to be encrypted can be any $alid te#t file with no more than &&&1 letters in it. 'Thus" it's safe to store all characters in the file in a character array of si(e 1))))" including any padding characters.)

Format of the File !toring the Cipherte"t

*ach line of output should ha$e e#actly +) lowercase letters on it" e#cept for the the last row 'possibly). These characters should correspond to the cipherte#t of encrypting all the letters in the input file.

#hat to $%rn In o&er #ebCo%r!e! Turn in a single file, hill.c or hill.java storing your solution to the problem.

Program 'ote! an Hint! You must read in a file that contains uppercase letters" lowercase letters and non,letter characters. Your program must distinguish between these three groups so that what gets encrypted is always a lowercase character and the output should always be a lowercase character. -ll non,letter characters in the file are simply skipped and not counted as part of the plainte#t. .ne possible breakdown to sol$e this problem is as follows: 1) /rite a section of code or function that reads in the input file into an char array of si(e 1))))" storing only the appropriate lowercase letters in the character array.

) /rite a section of code or function that takes as input the array from section 1 and the encryption key and produces an array of cipherte#t storing only lowercase letters.

!) /rite a section of code or function that takes as input the array storing the cipherte#t and outputs it to the output file in the format specified.

Sample Key File 3 1 1 6 3 3 1 5 2 7

Sample Inp%t File


CS: the science that deals with the theory and methods of processing information in digital computers, the design of computer hardware and software, and the applications of computers.

!: the de"elopment, implementation, and maintenance of computer hardware and software systems to organi#e and communicate information electronically. $%%re"iation: !

Computers are man&made tools that aid us in sol"ing other pro%lems. $ %iologist is trying to figure out how life wor's, physicists and chemists are trying to figure out how items react in our uni"erse, mathematicians are trying to figure out rules for man&made systems.

$ny research pro%lem that may impro"e a computer(s capa%ility of helping sol"e a pro%lem or any research pro%lem that sheds light a%out a new way to do something with a computer is part of CS.

)ost e*citing research: )edical $pplications +,*pert Systems for -iagnosis, .emote surgery, nano&de"ices with computing power to deli"er medicine, etc./, 0e need help trying to create a comprehensi"e ,). accessi%le to the right people only, Cars that can dri"e themsel"es 1 seems li'e the %est way we 'now how to sol"e lots of pro%lems is %y throwing lots of computing power at them, instead of loo'ing for elegant solutions. !his doesn(t sound e*citing, %ut it will %e e*citing when the results are achie"ed. +ie 0atson/

CS students tend to find 2o%s where they program at least some. n the process, they are sol"ing pro%lems. Challenges: t(s impossi%le to teach all the new languages3toys.

4ltimately, we 2ust need to teach our students how to thin', so that they can pic' up new things on their own. 5ur %iggest challenge is getting them to %uy into that.

,thical: 6ots, with security etc.

Corre!pon ing (%tp%t File


e%*p#niicn*taafus#p#sof#7hsnyd7tlyhdn*pgo#%#ts#soaygmapndy7rd2fhr%"y7"n"%dat%%r* w"io%o"f#c'gsfiy'istuols#2cduf"e#h%#ta72pd'f7"yeh%iffhhpn7f"ofh7mprlr'f2"craf#cn ii*"c%s*g*n2fr%s*pn7%ds'i#ild*em#powhf'istuols#2cduf"e#h%#ta72pd'uoerdfr"sp"72"e d2dcyhumwddam#nm**rw7wdlw%dn*stcl*lw7r22%#a*w"fopn7*lw%#pr*w"io7t%7ws#*lroa7rt%o "tfm%%eanpudndwee%22ygmg#'odemsppp2d"'t%'t%l%hdycpngyrhiwggo#ddgl*fn#s*cnmeeowwl h%cyhft*'t%7t%"i"gftfl'*tf2lgsr2*h2#hccdh7oi%7ugp"dda*oy7aa2m27wsnf"il%7t%"i"gft fl'*tf2lgsr2#suatn#%gh#g%niuoerdfsp#n*awou2mimg#'od"wrnrsuca#u%hf'iuyr*w"ioui7"u epno*nh'opwil**""sf7%"l772frfpa2yyusgd%wufcdetap"rom*%c2wye**#gysr2lrcscy*nw"rny eswi2"%*r'*iuyr*w"iomp#%slfh7'ae2la"ft%7u""owou2mii#l'es*wewi*m#nw%del#rwu#fn2la ir%*s"seef"lyrnw'm%2""nu22onaapdaplfy'cr'*'istuofreff*fefpdapa'p*idde'rnsrfwyepd *iif't'l%hdyconlof*7oimprlsm"r7%ngonhoisaga*mpdfayeh2dnmpwer*"hfms"a*#%o"fhaf7"" sonyduoolohagac'i#rmy22riyghh'msi'gd#n*h2lnp"sf"h'r""s#sdetuoog%fhg#hlhfre27i'** 'istuofreff*"lccramewpiawpph7%'7mfrerw7n*sgfrr""piuw%d%o"sdtwuw''"iltpscu*dfrefe wd#yh72dtp"ft%7usnt%s*2ygmioielpd'sn%ifnddeaamr""tln%%ihi'"ae2cplacno2dsce*%tpey ehle2s#tm'yc7pc"naeum**yehmg#''o%o"cg7#dl"sffremg#'od7og"gipgyowif"wg*n''y*mpdfa *r#2%yghclueoll*t7eomghh7c'pi"uimlcysm'h%dewtrodf#gsn%gp"%%ihi'%oyu*n*c%d"g7lrro myehaauyo"ceoa'#fapfregf%yehfl7pparilyw7ghh2%yus%r2%'goh'2freyehldo22ffer*c%r2ow i27r227i'yies%wmi27am#%hu2

Sample Program )%n *+!er inp%t in bol , 8lease enter the name of the file storing the 'ey. samplekey.txt 8lease enter the name of the file to encrypt. panelnotes.txt 8lease enter the name of the file to store the cipherte*t. panelnotes-enc.txt

You might also like