Q#1: Read pages 104 to 106 from the official book, and run in your laptop the co
ID: 3752043 • Letter: Q
Question
Q#1: Read pages 104 to 106 from the official book, and run in your laptop the corresponding program :
CaesarCipher. Generalize the test for a complete text.
Explain the changes that would have to be made to the program of code fragment 3.7 so that it could perform Caesar cipher for messages that are written in Arabic.
Here below the 36 UNICODES of the Arabic Characters. So, all occurrences of number 26 for English should be changed by 36. Instead of "A" you may change it by the code: 1575. As we don'f have uppercases in Arabic, you should change : the condition to msg[k]>=1575 (lowest code).
: 1575
: 1576
1577:
: 1578
: 1579
: 1580
: 1581
: 1582
: 1583
: 1584
: 1585
: 1586
: 1587
: 1588
: 1589
: 1590
: 1591
: 1592
: 1593
: 1594
1595:
1596:
1597:
1598:
1599:
1600:
1609:
: 1601
: 1602
: 1603
: 1604
: 1605
: 1606
: 1607
: 1608
: 1610
// sentence written in arabic " "
can you try doing it in code
Java allows us to "subtract two characters from each other, with an integer result equal to their separation distance in the encoding, Given a variablec that is known to be an uppercase letter, the Java computation.) C 4 Simple Cryptography with Strings and Character Aras Class for doing encryption and decryption using the Caesar An important application of character arrays and strings is cr is the science of secret messages. This field imvolves the in which a message, called the plaintext, is converned into a scrambled msi called the cipkertext Likewise, cryptography forming decryption, turning a ciphertext back into its or desired index j. As a sanity check, if character c is A'.then j-0. Whencis 'B I hiference is 1 be used as an index into our precompated encoder array, as il 2 public class CaesarCipher 5 Constructor that initializes the encryption and 7for (int k-0, kExplanation / Answer
PROGRAM
package caesercipher;
public class CaeserCipher {
protected char[] encoder = new char[36];
protected char[] decoder = new char[36];
public CaeserCipher(int rotation)
{
for(int k =0; k<36; k++)
{
encoder[k] = (char) (1575 + (k+rotation)%36);
decoder[k] = (char) (1575 + (k-rotation+36)%36);
}
}
public String encrypt(String message)
{
return transform(message,encoder);
}
public String decrypt(String secret)
{
return transform(secret,decoder);
}
private String transform(String original, char[] code)
{
char[] msg=original.toCharArray();
for(int k=0;k<msg.length;k++)
if(msg[k]>=1575)
{
int j=msg[k]-1575;
msg[k]=code[j];
}
return new String(msg);
}
public static void main(String[] args) {
CaeserCipher cipher=new CaeserCipher(3);
System.out.println("Encryption code = "+ new String(cipher.encoder));
System.out.println("Decryption code = "+ new String(cipher.decoder));
String message=" ";
String coded=cipher.encrypt(message);
System.out.println("Secret : "+coded);
String answer=cipher.decrypt(coded);
System.out.println("Message : "+answer);
}
}
Output
Encryption code =
Decryption code =
Secret :
Message :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.