The 7 Things I Know About Cyber Security After 25 Years | April 2024
Questions2
1. WEEK
TWO
Problems for Week 2
Here are the second week’s problems for the NCSS Challenge 2009! This is the first set of problems that will
count towards your overall score in the Challenge.
This is the printable (PDF) version. You will need to login to submit solutions to each problem:
http://challenge.ncss.edu.au/accounts/profile/
Our scoring system is simple: each question is worth 10 points. If you submit a solution that passes all of our
tests the first time you submit, you’ll get the full 10 points.
You can submit multiple times. No points will be deducted for the first four incorrect submissions, but on your 5th
incorrect submission for a single problem, one point will be deducted from your possible score for that problem.
Another point will be deducted on your 10th incorrect submission, and so on. It doesn’t hurt to try a problem --
if you submit a few times but don’t pass all of the tests, the points you have scored for other problems will not
be affected.
Good luck!
1 Better Biscuits for your Bucks
You have joined a startup that is about to go public with a new iPhone application. This application, called better
biscuits for their bucks, is going to help shoppers everywhere by comparing the value for money of two packets
of biscuits.
Your program should read four lines of input using raw_input. There are two lines for each packet of biscuits.
The first line is the cost of packet 1 of biscuits (as a float). The second line is the number of biscuits in packet 1
(as an integer). The third line is the cost of packet 2, and the fourth line is the number of biscuits in packet 2.
Output the packet that is the best value, that is, the packet with the lower price per biscuit. If packet 1 is better
value, your program should print:
packet 1
For example, if the first packet has 17 biscuits and costs $5.50 and the second packet has only 3 biscuits and costs
$4, then obviously the careful shopper will purchase the first packet.
The interaction with your program might look like this:
Cost of packet 1? 5.5
Biscuits in packet 1? 17
Cost of packet 2? 4
Biscuits in packet 2? 3
packet 1
If two packets provide equal value for money, then your program should output:
packet 1 or 2
Of course in this case, we would consider the appropriate course of action to be to purchase both packets (more
biscuits, you see), but we’ll leave that up to the shopper.
c National Computer Science School 2005-2009 1
2. NCSS Challenge (Beginners) WEEK TWO
Hint
We’re only going to test the output of your program — not anything you pass as the prompt for raw_input.
2 Pirate line counter
Pirate Bob still can’t speak correctly! His shipmates are starting to worry about other pirates stealing the buried
treasure, and so need to find someone who can understand what he’s saying. The key to understanding him might
be the rolling r at the end of his words, and want to find one of their fellow pirates who rolls their r’s a lot too, to
figure out what Bob’s saying.
Your task is to help them count how many lines contain a double lowercase r in different lines of text. The rr
can occur anywhere within a line, but the two r’s have to be next to each other with nothing else in between. You
will need to read in any number of lines of input (up to a blank line), and output the number of lines which have
at least one ’rr’ in them.
So for example, for the input
Yarr Har
the output would be
1
But for the input
Ahoy m’hearties
Yo ho ho and a bottle of rrrrum
Tharrrr be th’ treasure
The output would be
2
3 lerCrypto scramb
Secret Agent No. 86 is really impressed with the new cipher he’s come up with, for disguising secret messages
between covert operatives. It works by removing the last letter of a line, and adding that letter to the front of the
line instead. So the line:
Meet me on the bridge
Is cunningly disguised as:
eMeet me on the brid
Unfortunately, Agent 86’s boss (The Chief) wasn’t quite so impressed. He says Agent 86 needs to come up with
a cipher that obeys Kerckhoffs’ Principle: a cryptosystem should still be secure even if everything about the
system, except the key, is public knowledge. That is, his cipher should involve some kind of key so that even if
the enemy agents know how his cipher works, they can’t decipher it without also knowing the key.
After quite a lot of thought Agent 86 came up with the following improvement. The key will be an integer, say
n, and his new cipher will be the old one repeated n times.
For example, he can encrypt the message above using the key 3 by first writing:
eMeet me on the bridg
c National Computer Science School 2005-2009 2
3. NCSS Challenge (Beginners) WEEK TWO
Then:
geMeet me on the brid
and finally:
dgeMeet me on the bri
This takes a fair bit longer than the old cipher, so your task is to write a program to automate this. It will read
in multiple lines of input. The first line will be the key (an integer), and then after that will be the message to
encript (the plaintext), possibly spread over multiple lines. You need to print out the encrypted plaintext.
For example, given the input:
1
Meet me on the bridge
beware
pigeons
Your program should print out:
eMeet me on the bridg
ebewar
spigeon
4 Find the odd one out
Please help me debug this program! I’m having trouble with my logic skills.
I trying to write a program to do something very simple: I have to read in three lines and find the odd one out. I
know that two of the three lines will always be the same and the other one different. I want to print out only the
one that is different.
For example, if the input was:
Row, row, row your boat
Gently down the stream
Row, row, row your boat
It should print:
Gently down the stream
As another example, if the input was:
Row, row, row your boat
Gently down the stream
Gently down the stream
It should print:
Row, row, row your boat
Here is some code I wrote that I thought would do it, but it isn’t working. Can you please fix it for me?
c National Computer Science School 2005-2009 3
4. NCSS Challenge (Beginners) WEEK TWO
line1 = raw_input()
line2 = raw_input()
line3 = raw_input()
if line1 != line3:
if line2 != line3:
print line3
else:
if line1 = line3:
print line2
else:
print ’line1’
Hint
Start by downloading the file from here and trying to run it!
5 encrypt.reverse()
The following program uses a fairly simple set of transformations to encrypt its input (the plaintext), which is a
single line consisting of lower case letters and punctuation.
line = raw_input(’Enter the plaintext’)
line = line.replace(’o’, ’E’)
line = line.replace(’e’, ’O’)
line = line.replace(’ray’, ’YAR’)
line = line.replace(’yar’, ’RAY’)
split = len(line)/2
line = line[split:] + line[:split]
print line.upper()
Submit a program to read the output of this program, decrypt it and print out the original plaintext again.
Hint
Try running the program with various inputs. When you have written a solution, test it by running some inputs
through this program, then running the result through your code to make sure it gives the original back again.
c National Computer Science School 2005-2009 4