Debugging --------- Most of the coding went quite smoothly. The main problem encountered was that the % operator in C++ returns a negative number when the first operand is negative. However, x%n, when x is negative will always return a value in between -n+1 and 0. (Assuming that n is positive.) To alleviate this issue, we notice that (x+mn) = x (mod n). So, we can add any multiple of n to the original value and preserve our answer. We do so such that x+mn is definitively positive. The coding of the extended euclid's algorithm was perhaps the most difficult part of the program. Figuring out how the t variables worked took some time because I do the process by hand differently. The actual inverse keys were fairly easy to compute once I worked through the math. This work is included in a comment in the code. The file writing code was fairly straightforward. Only the alphabetic characters had to be translated. Casting took care of any potential issues. This formula worked the first time it was written. Testing ------- I wrote the driver program first before I did much testing so that I could test each function separately. For the first function, I ran it with several files. In paricular, I tried files with only alphabetic characters, then with files that had non-alphabetic characters. I also tried files with multiple lines to check that the lines in a file were preserved. In each case, the output file produced contained the desired characters. I made sure that each file had all possible 52 character letters in order to ensure that each got translated correctly. For the second function, I made sure to test it with both valid and invalid affine cipher keys. Of the valid keys, I tried several, mixing up the parity of b. Each of these worked fine. For the invalid keys, I made sure to try a few multiples of 2 for a as well as 13, since those are the distinct prime factors of 26. In the course of the testing, I tried all valid values of a, since each of these gives rise to a distinct c, and also would give an indication as to whether or not my inverse function was working. In reality, I should have tested my inverse function first. I ended up testing it in general, with several prime numbers n and various values of x, including multiples of n. Next I tried several relatively prime values of x and n, seeing if I got the correct inverse. Finally, I tried various combinations of x and n that had common factors ranging from a single prime number to many primes. In each case, the program worked correctly. Technically, 0 and negative values were tried, but for our purposes, we can require that both values be positive.