Page 1 of 6

Problem 059

Posted: Fri Feb 29, 2008 8:04 pm
by Slock
So I am trying to write the brute force cipher program. I thought I had everything right, example, when I encode my own message, it comes back out correctly. But when I deal with the cipher1.txt file I get gibberish constantly. For example, the first character when XOR'd with a-z it always produces a symbol. But this is supposed to be all english words.

So I did:

Code: Select all

for(int i=97; i<=122;i++)
		{
			int currVal = XOR(79,i);
			char c=new Character((char) currVal);
			PrintShop.print(""+c+PrintShop.nl());
		}

and that produces for the first letter:
Expand
.
-
,
+
*
)
(
'
&
%
$
#
"
!

?
>
=
<
;
:
9
8
7
6
5
If the password has to be 3 lower case letters, then it has to be one of a-z deciphering the first character.XOR(79,i)works fine, I've double checked it with the examples they give with answers in the problem text.

65 XOR 42 = 107, then 107 XOR 42 = 65. That works fine. Am I misunderstanding what lower case character is? is that more then just a-z (26 characters).

Re: Problem 59

Posted: Fri Feb 29, 2008 8:17 pm
by daniel.is.fischer
Well, english text can contain some special symbols, e.g. some books begin with a quotation mark, an apostrophe or a digit.

Re: Problem 59

Posted: Fri Feb 29, 2008 8:24 pm
by hk
The encrypted text does not only contain lower case letters, but also uppercase letters and other characters.

Re: Problem 59

Posted: Mon Mar 03, 2008 12:25 pm
by Slock
Oh, I got ya. That was my mistake then. I'll keep at it, Thank you.

Re: Problem 59

Posted: Mon Jun 23, 2008 11:14 pm
by Eureka
I don't think I quite understand this problem.
Is there just one technically correct answer or many technically correct answers but only one that we have to pick out by reading the most linguistically or grammatically correct one?

For example, even when I correctly encrypt my own code and then try to decrypt it, I come up with many different possible answers that contain only ASCII printable characters. Then I have to scan through them and find the decryption that makes sense (ie, readable English words). Is that how it's suppose to be done?

Re: Problem 59

Posted: Mon Jun 23, 2008 11:24 pm
by daniel.is.fischer
More or less. There are some characteristics plain english text has. Let your programme look for some of these, once you've found four or five, you have the key.

Re: Problem 59

Posted: Mon Jun 23, 2008 11:29 pm
by Eureka
I have generated 540 possible solutions for cypher1.txt containing ASCII printables but none of them reads remotely like English.
Should I post my code?

Thanks!

Re: Problem 59

Posted: Mon Jun 23, 2008 11:31 pm
by daniel.is.fischer
Don't post the code, PM it if it's a readable language.

Re: Problem 59

Posted: Mon Jun 23, 2008 11:55 pm
by daniel.is.fischer
One of them reads like english. To find out which, you should let your code scan for characteristics of such text, there's more to it than that it only consists of printable characters.

Re: Problem 59

Posted: Tue Jun 24, 2008 12:14 am
by Eureka
Oy, found it! Thanks a lot. Much appreciated. :D

Problem 59

Posted: Mon Dec 01, 2008 3:58 pm
by tiny
Hello

I found the key and unscrambled the text.
But...
When I add all the ascii values, the answer appears to be wrong.

Where can I look for?
Whitespace (asc 32)?
Newlines \n

Re: Problem 59

Posted: Mon Dec 01, 2008 7:04 pm
by Ikcelaks
That's the right value for space. Most languages have a function from characters to their ascii byte value (usually "ord"). Are you applying that function to each character in the decrypted string and summing the result?

One possible thing to look for (depending on the language) is that you're summing integers rather than bytes, which would quickly overflow. However, it would probably be pretty obvious if you were getting a result less than 256.

Re: Problem 59

Posted: Mon Dec 01, 2008 10:39 pm
by tiny
I'am summing up exactly 1200 characters.

For this problem I use python.
The ord() function is part of this language.

Re: Problem 59

Posted: Tue Dec 02, 2008 12:59 am
by Ikcelaks
I'am summing up exactly 1200 characters.
That might be the problem. I count 1201 characters.

Re: Problem 59

Posted: Tue Dec 02, 2008 1:38 am
by elendiastarman
Yeah, you might have to increase the end limit of your Python loop by 1 (It is rather annoying to me sometimes... :P).

Re: Problem 59

Posted: Tue Dec 02, 2008 3:22 am
by Ikcelaks
Isn't the "foreach" construct a hallmark of Python programming? Maps, folds, and foreach like patterns are the way to go these days. Almost every language supports some kind of automated iteration over data structures.

Re: Problem 59

Posted: Tue Dec 02, 2008 5:06 am
by sigh
Ikcelaks wrote:Isn't the "foreach" construct a hallmark of Python programming? Maps, folds, and foreach like patterns are the way to go these days. Almost every language supports some kind of automated iteration over data structures.
Indeed. Whenever possible iterate over the elements in the object, rather than the indexes. If you need the indexes, then use enumerate.

Simple example:

Code: Select all

for i, c in enumerate(string_object):
    print "Character in position %d is %s" %(i,c)
Most of the time you don't need the indexes so `for c in string_object` would suffice. This will help greatly reduce off-by-one errors :).

Re: Problem 59

Posted: Tue Dec 02, 2008 5:08 am
by quilan
Ikcelaks wrote:Isn't the "foreach" construct a hallmark of Python programming? Maps, folds, and foreach like patterns are the way to go these days. Almost every language supports some kind of automated iteration over data structures.
Technically, the 'for' is a 'foreach' all the time I believe. Just use enumerate to make cleaner code.

Re: Problem 59

Posted: Wed Dec 03, 2008 11:32 am
by tiny
Hello

All the loops did what they had to do, but the problem was the absence of a comma at the end of the file.

My program genrated a character after reading a comma, so the last character was forgotten.

Re: Problem 059

Posted: Sun May 30, 2010 11:46 pm
by whakamaru
Do the words of the question "common English words" imply an element of human judgement?
If so, may I use human judgement to guess that common English words will be seperated by common English spaces?
That gave me the key, so I wrote the code that does the XOR and adds up the ASCII. And get the wrong answer.!
Oh dear, so sad, too bad. Perhaps there is another valid key? I will persist, mainly coz I want to see how the 'experts' did it. Watch this space... next year.