# Duncan's blog

## November 9, 2008

### Project Euler: problem 79

Filed under: Project Euler — duncan @ 7:00 am
Tags: ,

Problem 79:

A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was 531278, they may asked for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.

The text file, keylog.txt, contains fifty successful login attempts.

Given that the three characters are always asked for in order, analyse the file so as to determine the shortest possible secret passcode of unknown length.

At first I started coding up a solution. It looked a bit complicated, so I decided to try it by hand with pen and paper. Doing it that way took about two minutes, much quicker than trying to code a solution! However if you were going to do this for say a hundred different users, you’d be better trying to work it out in code.

The theory would be to have an array, and insert each new digit encountered in the logins to the array. For each digit, check if it’s already in the array. If it is, compare its position against the next digit in the current block of three. If they’re not in the correct order in the array, shuffle them around until they are.

Doing it by hand, just draw ten columns on your page. Start putting the numbers into the array, manually working out where they should be each time. Doing it that way isn’t very hard at all…

Advertisements

## Leave a Comment »

No comments yet.

Create a free website or blog at WordPress.com.