# Finite Automata And The Recognition Problem

There are two problems you are required to solve as part of this assignment. Both require some knowledge about finite automata, and both are meant to have you learn more about FAs.

## Recognizing Numbers in Scientific Normal Form

A number is said to be represented in scientific notation if it is in the form of:

````           number = s * (r^exp)`
```

where number is the number in the scientific notation, s is called the significand, r is the radix (or base), and exp is the exponent. The number is said to be in normal form when the significand meets the criteria:

```           1 <= s < r
```

This rule implies that, for decimal numbers with no leading zeros, the decimal point always occurs at the right of the first significant symbol.

```Ex:       23.24        is not in scientific normal form (SNF) since the base and the
exponent are missing.

23.23*10^0   is not in SNF since the significand (23.24) is larger than
the base

2.324*10^1   is a number in SNF: the significand (2.324) is larger than 1
and smaller than 10, and it is multiplied by the base (10)
raised at some power (1).
```

For practical and historical reasons, numbers in scientific notation are entered in computers in a slightly different format: the base (understood to be 10) is replaced by a e or a E, and the caret sign (^) is omitted. For computer purposes, a number like 23.24 will be represented as 2.324e1 in SNF. Note that the number may have a leading sign (+ or -), and that the exponent itself can have a sign. The same number (23.24) can also be represented as +2.324e+1 where both the sign of the number and the sign of the exponent are present.

Your program will read a string from the keyboard and will decide whether the string represents a number in SNF or not. Note that you must make the decision regardless of whether the number is actually representable in the computer or not. For instance 1.414213562373095048801688724209698078569671875376948073176679737e0 would be a perfectly valid input to your program; however, you never get this many significant bits in any common computer representation.

If you like to think of programs as being something useful (beyond the learning experience), then you can imagine your program is part of a package which is used to train students in Computer Science: your program will then do part of the training which refers to number formats.

## A Security Device

Think of simulating a security installation. The installation has a keypad and an engine (a controller) used to decide whether the user has entered the correct access key or not. To keep things simple the keypad has only two keys, one labeled with '0' and another one labeled with '1'. The security engine will unlock the lock when it finds the correct access code in the input string. For example, let's assume that the access code is 110100. If the user enters the string 010111010010101, then the lock will be unlocked as soon as the engine finds the last correct letter of the access code in the input string. The engine locks the lock again if the user continues entering from the keypad past the last digit of the access code. With the input string mentioned before, the lock will be unlocked and then locked again.

Your program will read from the keyboard without echoing the input characters. Characters other than 0 and 1 will be quietly discarded. Your engine will recognize a fixed access code. The access code will be the binary representation of the number represented by the first four digits of your Social Security Number. Input characters are processed on the fly (not on a line basis). You will find a way to indicate when the unlocking/locking occurs (by printing a message, or beeping, etc).

You need do the following part only if you are looking for extra credit (20% for this assignment) or you want to have some more fun.

Since a possible intruder does not have any idea about how long the access string is, you think this security device may be quite effective. You decide to test it. One possible way to try to break the lock is to generate a random sequence of 0s and 1s as the input string. Of course, after each 0 or 1 input you should check to see whether the lock has been unlocked or not. This would naturally increase the time it takes an intruder to break your security mechanism.

• Try to estimate how long it would take (on the average) to break the lock. Assume the random number generator has a uniform distribution.
• Do the actual test: use some random number generator to generate the input string for the security device. Count how many symbols (0 or 1) have been generated before the lock is unlocked. Ignore the waiting time in this case and have the program run at full speed.

## What you'll turn in

1. Well commented listings of your programs (C or C++ is recommended but not required). Note that grading, as described below, considers both the functionality and the readability of your code. You may also want to have a look at a grading sheet used in the past for a similar assignment. If you are unsure about what the documentation of a program means, then you may want to read this document.
2. A floppy disk (3.5") which contains (in separate directories) the source files and a README file for each program indicating how to build the executable, what the program does, and what is the format of the input file and any of the output files.
3. A memo describing what you have done and how. In the memo clearly state which are the languages of the FAs you have implemented. Direct the memo to your class instructor. The memo attachments will include the state transition diagrams for your Finite Automata.

1. A mark between 0 and 10 for functionality. This mark basically indicates in what measure your program works properly.
2. A mark between 0 and 10 for readability. This mark indicates how well documented your program is, and how good is the report you turn in(the memo).
3. Multiply the above two marks to get the mark for this programming assignment.

## Varia

You don't need to be concerned about optimization(s). In particular you are not required to minimize the number of states in your FAs. You can do so if you want but this is not a must.

(c) 1996, Virgil Bistriceanu