Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help to fill out the missing part! USING AFFINE CIPER. how to calculate the frequencies of lettters in the ciphertext? public class Ciphercode {

Please help to fill out the missing part! USING AFFINE CIPER. how to calculate the frequencies of lettters in the ciphertext?

public class Ciphercode {

private static final String cipherText = "GWN GANBDJAN HWNDG ZD EJAZNK WNAN: " +

"DBZI QARL DFNINGRO ZDIBOK GR GWN NBDG-DRJGWNBDG. " +

"BQGNA GPR KBVD, VRJ PZII QZOK B KNDNAGNK ZDIBOK. " +

"HIZLE GR GWN WZTWNDG URZOG RQ GWN ZDIBOK BOK IRRF QRA B IBATN HIZQQ GR GWN ORAGW. " +

"PBIF B WJOKANK VBAKD GRPBAKD GWN HIZQQ BOK DGRU BG GWN GBII GANN. " +

"PBIF GNO QNNG GR GWN NBDG, BOK VRJ PZII QZOK B ARHF PZGW BO S UBZOGNK RO ZG. " +

"GWN GANBDJAN ZD EJAZNK RON QRRG ENIRP GWN ARHF. ";

static final int alphaIndex = (int) 'A';

static final int alphaLength = (int) 'Z' + 1 - (int) 'A';

// Missing part. needs to be filled out automatically based on the ciphertext

static int[] frequency = new int[alphaLength];

private static int decrypt(int index) {

// Missing part. ... decrypt ...

return index;

}

public static void main(String [] args) {

for (char cipherChar : cipherText.toCharArray())

if (Character.isLetter(cipherChar)) { // only letters are encrypted, punctuation marks and whitespace are not

// following line converts letters to numbers between 0 and 25

int cipher = (int) cipherChar - alphaIndex;

int plain = decrypt(cipher);

// following line coverts numbers between 0 and 25 to letters

char plainChar = (char) (plain + alphaIndex);

System.out.print(plainChar);

}

else

System.out.print(cipherChar);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions