When a message is transmitted in secret code over a transmission channel, it is
ID: 3884085 • Letter: W
Question
When a message is transmitted in secret code over a transmission channel, it is usually transmitted as a sequence of bits, i.e., Os and Is. Due to noise in the transmission channel, the transmitted message may become corrupted This means that the message received at the destination is not the same as the message transmitted, some of the bits may have been changed There are several techniques to check the validity of the transmitted message at the destination. One technique is to transmit the same message twice. At the destination, both copies of the message are compared bit-by-bit. If the corresponding bits are the same, the message received is error-free. Write a Java program that implements a readCode method and compareCode method to check whether the message received at the destination is error- free Assume that the secret code representing the message is a sequence of digits (0 to 9) and the maximum length of the message is 250 digits. Also, the first number in the message is the length of the message. For example, if the secret code is: 7 9 2 7 8 3 5 6 then the message is 7 digits long, and it is transmitted twice. The above message is transmitted as: 7 9 2 7 8 3 5 6 7 9 2 7 8 3 5 6 Use the following files: The input file called SecretCode.txt contains the secret code and its copy: 7 9 2 7 8 3 5 6 7 9 2 7 8 3 5 6 The output file called SecretCodeOut.txt should contain 2 columns of digits labeled Code Digit and Code Digit Copy along with the message underneath both 2 columns that reads: "Message transmitted OK" Print out both input and output files along with your source code.Explanation / Answer
public class Decoder{
public ststic void main(string[] args){
try{
BufferReader in-new Bufferedreader(new InputStream Reader(System.in));
int k=Integer.ParseInt(in.readline());
stringword=in.readline();
char[] carray=word.tocharArray();
for(int i=0;i<word();i++){
char out=(char)((carray[i]-(((3*(i+1))+k)%('z'-'A')));
if(out<'A'){
char wrap=(char)(('Z'+1-('A'-out));
system.out.print(wrap);
}else
{
system.out.print(out);
}
}
}catch (IOException e){
system.out.println("error");
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.