% % For CSC148H Summer 96, Assignment 2: Data Encryption % % % VERIFY (THIS IS THE NEW VERSION) % % This function will verify that a substitution table is valid. % It will return true if so, false otherwise. % The two boolean arrays, verify_plain and verify_cipher, are filled in % with true for each plaintext letter and ciphertext letter in the % substitution table. (Note: the array indexes refer to the position in % the alphabet in the range 1..ALPHA_SIZE of each letter, where ALPHA_SIZE % is a constant whose value is the size of the alphabet---26 letters). % % If, during this, an entry in either array is already true, then the % table is invalid. Why? % % The only parameter is the substitution table of type subsTableType. % YOU HAVE TO DEFINE THIS TYPE % function verify_table (subs_table : subsTableType) : boolean var verify_plain : array 1 .. ALPHA_SIZE of boolean var verify_cipher : array 1 .. ALPHA_SIZE of boolean % initialize the arrays to all false for j : 1 .. ALPHA_SIZE verify_plain (j) := false verify_cipher (j) := false end for %%%%%%%%% MAIN LOOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % loop through all entries in the substitution table, % i refers to the current entry (which contains a mapping from % a single plaintext letter to a ciphertext letter (e.g., "a"->"h")) % % We assume its valid, then set 'valid' to false if its not % var i : int := 1 var valid := true % <---------------NEW % PRECONDITION assert ( PUT YOUR PRECONDITION(S) HERE ) % loop through the entries loop % LOOP INVARIANT invariant ( PUT YOUR INVARIANT(S) HERE ) exit when (i > ALPHA_SIZE) % THE PART IN [] DEPENDS ON YOUR DEFINITION OF THE subsTableType % var index_plain := [position in alphabet of the plaintext letter % in the ith table entry] if verify_plain (index_plain) then valid := false % <------------------NEW else verify_plain (index_plain) := true end if % var index_cipher := [position in alphabet of the ciphertext letter % in the ith table entry] if verify_cipher (index_cipher) then valid := false % <------------------NEW else verify_cipher (index_cipher) := true end if i := i + 1 end loop % POSTCONDITION assert ( PUT YOUR POSTCONDITION(S) HERE ) % %%%%%%% end of MAIN LOOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if any entry is still false, then the table is invalid result valid end verify_table