The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

319584 (3) [Avatar] Offline
#1
Chapter 1.4 on calculating pi: the code of the function calculatePi has to return abs(pi) in order to get a positive value. It turns out that the full sequence of terms is negative only because of the initial -1 value of operation. Starting with 1 would result in only positive terms:

func calculatePi (terms: Int) -> Double {
    ...
    var operation: Double = 1  // starting with positive value for the first and largest term
    var pi: Double = 0
    for _ in 0..<terms {
        ...
    }
    return pi                  // avoids having to return absolute value 
}
319584 (3) [Avatar] Offline
#2
Chapter 1.3 on OPT encryption:

Figure 1.6 is confusing, because there is no real dummy data: what is called dummy in the picture is in fact the one time pass phrase (OTP). The first picture does further not match the code, because "dummy" (so in reality the OTP) is shown as input and as output, whereas in the code it is generated randomly and is not an input. Couldn't the schema be aligned with the code ?

Renaming the components of the OTPKeyPair into otpkey and cypher instead of the too abstract key1 and key2 could help the reader to understand better the purpose of each. Similarly, the readability of the encryptOTP code snippet could be increased by renaming dummy into passphrase or key (if possible use the same term than in figure 1.6).
David Kopec (15) [Avatar] Offline
#3
Hi @319584,

Thanks for the suggestions! The simplification of the pi calculation code is great. If there is another edition of the book I will update it. I disagree with you on the use of the term "dummy" as well as the diagram for OTP encryption example. I understand what you're saying, but I think for most readers, especially those with no prior encryption training, thinking about the random data as "dummy" data and seeing it as "input" to the XOR method makes intuitive sense. It depends on your semantic use of the word "input."

Thanks for reading!
Best,
DK
319584 (3) [Avatar] Offline
#4
Thank you for your answer. I'll continue on this thread with further suggestions