Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that decrypts the following message: :mmZ\\dxZmx]Zpgy Messa

ID: 3704510 • Letter: W

Question

Write a Java program that decrypts the following message:
:mmZdxZmx]Zpgy
Message is encrypted using the enemy's secret code. You have just learned that their encryption method is based upon the ASCII code. Individual characters in a string are encoded using this system. For example, the letter "A"is encoded using the numbers 65 and "B" is encoded using the numbers 66.
Your enemy's secret code takes each letter of the message and encrypts it as follows:-
if(originalChar + key > 126) then encryptedChar = 32 + ((originalChar + key)-127) else encryptedChar = (originalChar + key)
For example, if the enemy uses key = 10, then the message "Hey" would be encrypted as:-
Character   ASCII Code
H   72
e   101
y   121
Encrypted H = (72 + 10) = 82 = R in ASCII
Encrypted e = (101 + 10) = 111 = o in ASCII
Encrypted y = 32 + ((121 + 10) - 127) = 36 = $ in ASCII
Consequently, "Hey" would be translated as "Ro$" in ASCII
Write a program that decrypts the intercepted message. The ASCII codes for the unencrypted message are limited to the visible ASCII characters. You only know that the key used is a number between 1 and 100. Your program should try to decode the message using all possible keys between 1 and 100. When you try the valid key, the message will make sense. For all other keys, the message will appear as gibberish.

Write comments on or near each line of code explaining what it does and submit a picture of the programs output. Also make sure it works on netbeans. The answer should be Attack at dawn.

Explanation / Answer

Please find the below code.

import java.util.Scanner;

public class Decrypt {

public static void main(String[] args) {

String cipher = "";

Scanner sc = new Scanner(System.in);

cipher = sc.next();

for (int key = 1; key <= 100; key++) {

String plain = "";

for (char c : cipher.toCharArray()) {

if((c-key)<32) {

plain+=(char)(c-key+127-32);

} else

plain+=(char)(c-key);

}

System.out.println("Plain text for key " + key + " is: " + plain);

}

}

}

The answer is Attack the Dawn! for key 88.

Sample Input:

:mmZdxZmx]Zpgy

Sample Output:

Plain text for key 1 is: 9llY[cwYlwYofx
Plain text for key 2 is: 8kkXZbvXkv[Xnew
Plain text for key 3 is: 7jjWYauWjuZWmdv
Plain text for key 4 is: 6iiVX`tVitYVlcu
Plain text for key 5 is: 5hhUW_sUhsXUkbt
Plain text for key 6 is: 4ggTV^rTgrWTjas
Plain text for key 7 is: 3ffSU]qSfqVSi`r
Plain text for key 8 is: 2eeRTpRepURh_q
Plain text for key 9 is: 1ddQS[oQdoTQg^p
Plain text for key 10 is: 0ccPRZnPcnSPf]o
Plain text for key 11 is: /bbOQYmObmROe
Plain text for key 12 is: .aaNPXlNalQNd[m
Plain text for key 13 is: -``MOWkM`kPMcZl
Plain text for key 14 is: ,__LNVjL_jOLbYk
Plain text for key 15 is: +^^KMUiK^iNKaXj
Plain text for key 16 is: *]]JLThJ]hMJ`Wi
Plain text for key 17 is: )\IKSgIgLI_Vh
Plain text for key 18 is: ([[HJRfH[fKH^Ug
Plain text for key 19 is: 'ZZGIQeGZeJG]Tf
Plain text for key 20 is: &YYFHPdFYdIFSe
Plain text for key 21 is: %XXEGOcEXcHE[Rd
Plain text for key 22 is: $WWDFNbDWbGDZQc
Plain text for key 23 is: #VVCEMaCVaFCYPb
Plain text for key 24 is: "UUBDL`BU`EBXOa
Plain text for key 25 is: !TTACK_AT_DAWN`
Plain text for key 26 is: SS@BJ^@S^C@VM_
Plain text for key 27 is: ~RR?AI]?R]B?UL^
Plain text for key 28 is: }QQ>@H>QA>TK]
Plain text for key 29 is: |PP=?G[=P[@=SJ
Plain text for key 30 is: {OO<>FZ<OZ?<RI[
Plain text for key 31 is: zNN;=EY;NY>;QHZ
Plain text for key 32 is: yMM:<DX:MX=:PGY
Plain text for key 33 is: xLL9;CW9LW<9OFX
Plain text for key 34 is: wKK8:BV8KV;8NEW
Plain text for key 35 is: vJJ79AU7JU:7MDV
Plain text for key 36 is: uII68@T6IT96LCU
Plain text for key 37 is: tHH57?S5HS85KBT
Plain text for key 38 is: sGG46>R4GR74JAS
Plain text for key 39 is: rFF35=Q3FQ63I@R
Plain text for key 40 is: qEE24<P2EP52H?Q
Plain text for key 41 is: pDD13;O1DO41G>P
Plain text for key 42 is: oCC02:N0CN30F=O
Plain text for key 43 is: nBB/19M/BM2/E<N
Plain text for key 44 is: mAA.08L.AL1.D;M
Plain text for key 45 is: l@@-/7K-@K0-C:L
Plain text for key 46 is: k??,.6J,?J/,B9K
Plain text for key 47 is: j>>+-5I+>I.+A8J
Plain text for key 48 is: i==*,4H*=H-*@7I
Plain text for key 49 is: h<<)+3G)<G,)?6H
Plain text for key 50 is: g;;(*2F(;F+(>5G
Plain text for key 51 is: f::')1E':E*'=4F
Plain text for key 52 is: e99&(0D&9D)&<3E
Plain text for key 53 is: d88%'/C%8C(%;2D
Plain text for key 54 is: c77$&.B$7B'$:1C
Plain text for key 55 is: b66#%-A#6A&#90B
Plain text for key 56 is: a55"$,@"5@%"8/A
Plain text for key 57 is: `44!#+?!4?$!7.@
Plain text for key 58 is: _33 "*> 3># 6-?
Plain text for key 59 is: ^22~!)=~2="~5,>
Plain text for key 60 is: ]11} (<}1<!}4+=
Plain text for key 61 is: |~';|0; |3*<
Plain text for key 62 is: [//{}&:{/:~{2);
Plain text for key 63 is: Z..z|%9z.9}z1(:
Plain text for key 64 is: Y--y{$8y-8|y0'9
Plain text for key 65 is: X,,xz#7x,7{x/&8
Plain text for key 66 is: W++wy"6w+6zw.%7
Plain text for key 67 is: V**vx!5v*5yv-$6
Plain text for key 68 is: U))uw 4u)4xu,#5
Plain text for key 69 is: T((tv~3t(3wt+"4
Plain text for key 70 is: S''su}2s'2vs*!3
Plain text for key 71 is: R&&rt|1r&1ur) 2
Plain text for key 72 is: Q%%qs{0q%0tq(~1
Plain text for key 73 is: P$$prz/p$/sp'}0
Plain text for key 74 is: O##oqy.o#.ro&|/
Plain text for key 75 is: N""npx-n"-qn%{.
Plain text for key 76 is: M!!mow,m!,pm$z-
Plain text for key 77 is: L lnv+l +ol#y,
Plain text for key 78 is: K~~kmu*k~*nk"x+
Plain text for key 79 is: J}}jlt)j})mj!w*
Plain text for key 80 is: I||iks(i|(li v)
Plain text for key 81 is: H{{hjr'h{'kh~u(
Plain text for key 82 is: Gzzgiq&gz&jg}t'
Plain text for key 83 is: Fyyfhp%fy%if|s&
Plain text for key 84 is: Exxego$ex$he{r%
Plain text for key 85 is: Dwwdfn#dw#gdzq$
Plain text for key 86 is: Cvvcem"cv"fcyp#
Plain text for key 87 is: Buubdl!bu!ebxo"
Plain text for key 88 is: Attack at dawn!
Plain text for key 89 is: @ss`bj~`s~c`vm
Plain text for key 90 is: ?rr_ai}_r}b_ul~
Plain text for key 91 is: >qq^`h|^q|a^tk}
Plain text for key 92 is: =pp]_g{]p{`]sj|
Plain text for key 93 is: <oo^fzoz_ i{
Plain text for key 94 is: ;nn[]ey[ny^[qhz
Plain text for key 95 is: :mmZdxZmx]Zpgy
Plain text for key 96 is: 9llY[cwYlwYofx
Plain text for key 97 is: 8kkXZbvXkv[Xnew
Plain text for key 98 is: 7jjWYauWjuZWmdv
Plain text for key 99 is: 6iiVX`tVitYVlcu
Plain text for key 100 is: 5hhUW_sUhsXUkbt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote