Efficient LFSR. The given solution to Exercise 7.1.15 is not useful for large n because it runs in quadratic time (as does any program that appends characters to a string one at a time) and the sequence repeats after 211 − 1 bits. Develop a version of the program that fixes the second problem by replacing 11 by 63 and 9 by 62 (and takes 63 0/1 characters as its first argument), and fixes the first problem by keeping track of only the previous 63 bits printed.
Exercise 7.1.15
LFSR. Write a Java program that uses an abstract linear feedback shift register (LFSR) to generate a “random” sequence bits. That is, your program is to simulate the operation of a 12-bit register like this:
The register repeatedly computes the XOR of bits 11 and 9, puts the result in bit 0 and outputs it, and then shifts all the bits one position to the left. In your program, use 0 and 1 characters to represent bits, as in Exercise 7.1.18, and use the following method: Take 11 bits as a string argument. Then take an integer n from the second command-line argument and create a string of length n by performing the following operation n − 11 times: to compute the ith bit (character) append the exclusive or of the bits (characters) at positions (i − 11) and (i − 9). Your program should behave as follows:
Exercise 7.1.18
Encryption/decryption machine. Develop a Java program Crypto that reads two equal-length strings of 0 and 1 characters from standard input, interprets those characters as bits, and writes the 0/1 string corresponding to the bitwise XOR of the two inputs. That is, your program should behave as follows:
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here