Please enable JavaScript to use CodeHS

Code Verification

In this project, students write a program to test and verify simulated random security codes generated two devices.

Easy

2 Hours

High School

Project Description

Background

You are in charge of cybersecurity for your company and you decide to provide employees with a code generator that they will use with their password to help verify logging in.


Unfortunately something has gone wrong. The codes that the employees are using are not matching up to the code that your company is using.


Your Task

Your boss has asked for a report. She wants you to figure out how many codes are matching between the employee’s key and the company’s key.


To do this, you need to take each of the next values generated, convert them to a 32 bit binary number, then compare the lowest 12 bits of both values. You want to keep track of the number of times those parts of the values match.


The keys both work on the same principle. To create its next value, a generator will take the previous value it produced and multiply it by a factor (employee key uses 692 and company key uses 483). It then keeps the remainder when dividing that resulting product by 308947. That final remainder is the value it produces next.


Here is an example:
Suppose that for starting values, the employee key uses 1427, while the company key uses 124. Then, the first five pairs of generated values are:


–Emp Key–    –Com Key–
  60643           59892
  257111           195765
276287              16713
 261358            39757
  125741             47917


In binary, these pairs are (with the employee’s value first in each pair):

00000000000000001110110011100011
00000000000000001110100111110100

00000000000000111110110001010111
00000000000000101111110010110101

00000000000001000011011100111111
00000000000000000100000101001001

00000000000000111111110011101110
00000000000000001001101101001101

00000000000000011110101100101101
00000000000000001011101100101101


Here, you can see that the lowest (here, rightmost) 12 bits of the fifth value match: 101100101101. Because of this one match, after processing these five pairs, you would report only 1 match.


In your program, prompt the user for the number of pairs that they would like to compare and then print out the number of matches.

Project Demo

Explore this program before assigning it!

Project Overview

Here is an outline of the project activities: