Prog 2: Decrypt
Descripton
Encryption is used to securely transmit information, be it credit card banking information or your passwords. In this program we will explore a simple approach to encryption / decryption called the Caesar Cipher. The Notes below describe the various stages of development for this program and what running the program should look like at each stage.
Notes:
The 55 points for correct execution of your program (see syllabus!) are broken down as shown below. In creating your program you may not use material that we have not yet covered in class (such as additional user-created methods or arrays.) Failing to follow this requirement will result in a 15 point deduction.
( 0 points) Click on this sample code to download it and use it as your starting point. The first step is to display the menu options and write brief code for each menu option so you know you got to the right place in your code when you run it. The "exit" option shouldn't do anything besides display a message that you got there. Running your program should look like:
Author: Dale Reed TA: Sean Deitz, Wed 5am Program: #2, Decrypt Enter input string: abc xyz You entered: ABC XYZ Select one of the following: 1. Encode input line 2. Decode input line 3. Exit program Your choice => 1 Encode chosen. Done with program.
( 10 points) Now actually do the encoding. Convert the user input String into all upper case using the String toUpper() method. Create a new String to store the new characters. Set the encoding transposition value to be 1 for now, and leave the output in forwards order. Pull out the characters in the user input line one at a time using the charAt() method. Using a for loop is helpful to do this. Leave blank characters unchanged. Take each alphabetic character (you may assume all input is alphabetic) and add the transposition value, wrapping around so that 'Z' + 1 becomes 'A'. One way to do this is using the mod operator (%) to wrap around.
Probably the variable you use to store individual characters will be declared as a char. After adding the transposition value to it you will likely need to cast the result back into a char to avoid compiler errors. Append each character to the new String being created one character at a time. Once you've processed all the characters, print out the string. Running this version should look like:
Author: Dale Reed TA: Sean Deitz, Wed 5am Program: #2, Decrypt Enter input string: abc xyz You entered: ABC XYZ Select one of the following: 1. Encode input line 2. Decode input line 3. Exit program Your choice => 1 Encode chosen. Encoded line is: BCD YZA Done with program.
( 20 points) Now change your program so that instead of always using 1 as the transposition value, you choose some random number between 1 and 25. See this program for an example of how to use a random number generator. Also you will need to generate a second random number between 0 and 1 (which will give 0 or 1) to choose the direction. A value of 0 should be the forwards direction, and a value of 1 should be the backwards direction. If the backwards direction is chosen, then as encoded characters are created, prepend them to the beginning of the new String instead of appending them to the end, thus reversing the result. Running this version should look like:
Author: Dale Reed TA: Sean Deitz, Wed 5am Program: #2, Decrypt Enter input string: abc xyz You entered: ABC XYZ Select one of the following: 1. Encode input line 2. Decode input line 3. Exit program Your choice => 1 Encode chosen. Encoding with transposition of 8 in a backwards direction. Encoded line is: HGF KJI Done with program.
( 25 points) Write the code to decode an input String. It should try all transposition values and both forwards and backwards directions, displaying all 52 results in two columns. The forwards direction results should be in the left column, and the backwards direction results should be in the right column. Running this version should look like:
Author: Dale Reed TA: Sean Deitz, Wed 5am Program: #2, Decrypt Enter input string: FNRC QRYEVUJ RMVYNHFVI You entered: FNRC QRYEVUJ RMVYNHFVI Select one of the following: 1. Encode input line 2. Decode input line 3. Exit program Your choice => 2 Decode chosen. Showing all possible results in forwards direction on the left and backwards direction on the right. GOSD RSZFWVK SNWZOIGWJ JWGIOZWNS KVWFZSR DSOG HPTE STAGXWL TOXAPJHXK KXHJPAXOT LWXGATS ETPH IQUF TUBHYXM UPYBQKIYL LYIKQBYPU MXYHBUT FUQI JRVG UVCIZYN VQZCRLJZM MZJLRCZQV NYZICVU GVRJ KSWH VWDJAZO WRADSMKAN NAKMSDARW OZAJDWV HWSK LTXI WXEKBAP XSBETNLBO OBLNTEBSX PABKEXW IXTL MUYJ XYFLCBQ YTCFUOMCP PCMOUFCTY QBCLFYX JYUM NVZK YZGMDCR ZUDGVPNDQ QDNPVGDUZ RCDMGZY KZVN OWAL ZAHNEDS AVEHWQOER REOQWHEVA SDENHAZ LAWO PXBM ABIOFET BWFIXRPFS SFPRXIFWB TEFOIBA MBXP QYCN BCJPGFU CXGJYSQGT TGQSYJGXC UFGPJCB NCYQ RZDO CDKQHGV DYHKZTRHU UHRTZKHYD VGHQKDC ODZR SAEP DELRIHW EZILAUSIV VISUALIZE WHIRLED PEAS TBFQ EFMSJIX FAJMBVTJW WJTVBMJAF XIJSMFE QFBT UCGR FGNTKJY GBKNCWUKX XKUWCNKBG YJKTNGF RGCU VDHS GHOULKZ HCLODXVLY YLVXDOLCH ZKLUOHG SHDV WEIT HIPVMLA IDMPEYWMZ ZMWYEPMDI ALMVPIH TIEW XFJU IJQWNMB JENQFZXNA ANXZFQNEJ BMNWQJI UJFX YGKV JKRXONC KFORGAYOB BOYAGROFK CNOXRKJ VKGY ZHLW KLSYPOD LGPSHBZPC CPZBHSPGL DOPYSLK WLHZ AIMX LMTZQPE MHQTICAQD DQACITQHM EPQZTML XMIA BJNY MNUARQF NIRUJDBRE ERBDJURIN FQRAUNM YNJB CKOZ NOVBSRG OJSVKECSF FSCEKVSJO GRSBVON ZOKC DLPA OPWCTSH PKTWLFDTG GTDFLWTKP HSTCWPO APLD EMQB PQXDUTI QLUXMGEUH HUEGMXULQ ITUDXQP BQME Done with program.
You will then need to look at the results to see which line gives words in English, and whether it is in the fowards (left) or reverse (right) column.
( 10 points extra credit) Have your program automatically figure out which combination of transposition value (1..25) and direction (forwards or reverse) gives the correct answer. You may assume the input is some common English sentence containing common words in English. Use this list of most common English words to help your program figure out when the result is in English. For each of the first 50 (or more) words on this list you should see if your resulting String contains that word (I recommend using the String contains() method). If so, accumulate a score. For each transposition value and direction also display the corresponding score, shown in parenthesis at the end of each entry below. Remember the transposition amount and direction for the combination that gives the best score. Then apply these and give the correct output at the end. Running this version would look like:
Author: Dale Reed TA: Sean Deitz, Wed 5am Program: #2, Decrypt Enter input string: LSA AEW M XS ORSA MX ASYPH IRH XLMW AEC You entered: LSA AEW M XS ORSA MX ASYPH IRH XLMW AEC Select one of the following: 1. Encode input line 2. Decode input line 3. Exit program Your choice => 2 Decode chosen. Showing all possible results in forwards direction on the left and backwards direction on the right. 1.MTB BFX N YT PSTB NY BTZQI JSI YMNX BFD (0) DFB XNMY ISJ IQZTB YN BTSP TY N XFB BTM (0) 2.NUC CGY O ZU QTUC OZ CUARJ KTJ ZNOY CGE (0) EGC YONZ JTK JRAUC ZO CUTQ UZ O YGC CUN (0) 3.OVD DHZ P AV RUVD PA DVBSK LUK AOPZ DHF (0) FHD ZPOA KUL KSBVD AP DVUR VA P ZHD DVO (0) 4.PWE EIA Q BW SVWE QB EWCTL MVL BPQA EIG (0) GIE AQPB LVM LTCWE BQ EWVS WB Q AIE EWP (0) 5.QXF FJB R CX TWXF RC FXDUM NWM CQRB FJH (0) HJF BRQC MWN MUDXF CR FXWT XC R BJF FXQ (0) 6.RYG GKC S DY UXYG SD GYEVN OXN DRSC GKI (0) IKG CSRD NXO NVEYG DS GYXU YD S CKG GYR (0) 7.SZH HLD T EZ VYZH TE HZFWO PYO ESTD HLJ (0) JLH DTSE OYP OWFZH ET HZYV ZE T DLH HZS (0) 8.TAI IME U FA WZAI UF IAGXP QZP FTUE IMK (0) KMI EUTF PZQ PXGAI FU IAZW AF U EMI IAT (0) 9.UBJ JNF V GB XABJ VG JBHYQ RAQ GUVF JNL (0) LNJ FVUG QAR QYHBJ GV JBAX BG V FNJ JBU (0) 10.VCK KOG W HC YBCK WH KCIZR SBR HVWG KOM (0) MOK GWVH RBS RZICK HW KCBY CH W GOK KCV (0) 11.WDL LPH X ID ZCDL XI LDJAS TCS IWXH LPN (0) NPL HXWI SCT SAJDL IX LDCZ DI X HPL LDW (0) 12.XEM MQI Y JE ADEM YJ MEKBT UDT JXYI MQO (0) OQM IYXJ TDU TBKEM JY MEDA EJ Y IQM MEX (0) 13.YFN NRJ Z KF BEFN ZK NFLCU VEU KYZJ NRP (0) PRN JZYK UEV UCLFN KZ NFEB FK Z JRN NFY (0) 14.ZGO OSK A LG CFGO AL OGMDV WFV LZAK OSQ (1) QSO KAZL VFW VDMGO LA OGFC GL A KSO OGZ (1) 15.AHP PTL B MH DGHP BM PHNEW XGW MABL PTR (0) RTP LBAM WGX WENHP MB PHGD HM B LTP PHA (0) 16.BIQ QUM C NI EHIQ CN QIOFX YHX NBCM QUS (0) SUQ MCBN XHY XFOIQ NC QIHE IN C MUQ QIB (1) 17.CJR RVN D OJ FIJR DO RJPGY ZIY OCDN RVT (1) TVR NDCO YIZ YGPJR OD RJIF JO D NVR RJC (0) 18.DKS SWO E PK GJKS EP SKQHZ AJZ PDEO SWU (0) UWS OEDP ZJA ZHQKS PE SKJG KP E OWS SKD (0) 19.ELT TXP F QL HKLT FQ TLRIA BKA QEFP TXV (0) VXT PFEQ AKB AIRLT QF TLKH LQ F PXT TLE (0) 20.FMU UYQ G RM ILMU GR UMSJB CLB RFGQ UYW (0) WYU QGFR BLC BJSMU RG UMLI MR G QYU UMF (0) 21.GNV VZR H SN JMNV HS VNTKC DMC SGHR VZX (0) XZV RHGS CMD CKTNV SH VNMJ NS H RZV VNG (0) 22.HOW WAS I TO KNOW IT WOULD END THIS WAY (7) YAW SIHT DNE DLUOW TI WONK OT I SAW WOH (1) 23.IPX XBT J UP LOPX JU XPVME FOE UIJT XBZ (0) ZBX TJIU EOF EMVPX UJ XPOL PU J TBX XPI (0) 24.JQY YCU K VQ MPQY KV YQWNF GPF VJKU YCA (0) ACY UKJV FPG FNWQY VK YQPM QV K UCY YQJ (0) 25.KRZ ZDV L WR NQRZ LW ZRXOG HQG WKLV ZDB (0) BDZ VLKW GQH GOXRZ WL ZRQN RW L VDZ ZRK (0) 22. HOW WAS I TO KNOW IT WOULD END THIS WAY Done with program.
Turning it In
Turn in your program using Blackboard before 11:59 pm (just before midnight) on the deadline given on the course schedule. I highly recommend you review the grading criteria given in the syllabus before you turn in your program. Note that you can turn in your program multiple times, but only the last submission will be graded.