INVITATION TO CYBERSECURITY 22 tions that a CPU can actually execute. Computer programs are made up of just three basic types of statements: sequential statements, conditional statements, and looping statements. Sequential just means one after the other. You read a book sequentially, one word, one sentence, one page, after the other. A conditional statement is like a fork in the road (although they are not limited to just two paths) that can take the program down alternative routes based on its inputs. Some books employ a conditional construct—the “choose your own adventure” stories written for children where the reader encounters sentences like, “If Johnny opens the scary door, go to page 10, but if Johnny runs the other way, go to page 20.” Just like this example, the if-statement is a typical conditional statement keyword employed by high level programming languages. A keyword is a reserved word in the programming language with a predefined meaning. Looping statements direct the program to repeat the same sequence of instructions over and over again until a condition is met. Loops are how the same algorithm can sort short lists or long lists of words—the loop will continue until there are no words left to process. For a list of five words the loop will repeat five times, but for a list containing thousands of words, the same loop will repeat thousands of times. The for-statement and the while-statement are the typical looping keywords in high-level programming languages. Sequential, conditional, and looping constructs can be combined and nested in an infinite number of ways to form algorithms, and these algorithms can be encapsulated into black boxes called procedures, which then become usable by other algorithms, and so on. So in the same way computer hardware can be encapsulated and abstracted, so can computer software. At the highest level of abstraction, a program may be relatively simple to understand as a list of procedures (see Figure 2.7). Procedures can take zero, one, or more arguments as input that are indicated within parentheses following the procedure name. Any non-trivial computer program is composed of many procedures, and procedures typically call other procedures to perform sub-tasks, and so on. Software libraries are groups of related procedures that can be imported into a program. Rather than reinventing the wheel, programmers can just find the procedure they need in a library and call it. Software libraries that perform common tasks can become very popular. These libraries are used and reused many times over by lots of different programmers. Figure 2.7 Pseudocode for sorting a list of words made up of three procedures. Programs must be tested to be sure they produce the correct outputs because programming is difficult. In one sense, programs always produce the “correct” outputs—meaning the outputs they were specified to produce. However, the specified outputs do not always match a programmer’s intended outputs! Programming mistakes occur frequently and are called bugs. Sometimes bugs lead to cybersecurity issues.
RkJQdWJsaXNoZXIy MTM4ODY=