1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2012
Posts
1
Rep Power
0

#### XOR question

I really need someone to help me understand what is happening in a piece of this Python pseudocode.

Code:
```input ← user input
key ← “Jonathan's awesome hash function”
//pad input to ensure the length is a multiple of 32
//this will append the necessary number of bytes from
// the beginning of the key
if length(input) == 0 || length(input) % 32:
input += key[:32-length(input)%32]
hash ← key
for block_32 in input: //break input into 32-byte blocks
hash ← hash xor block_32
if hash[0] % 2: // WHAT IS THIS?
for i in [0, 32):
//increment each byte by 42 (modulo 256)
hash[i] ← (hash[i] + 42) % 256 // HASH[i]??
if hash[1] % 3: //WHAT IS THIS?
//move the first 10 bytes to the end
hash ← hash[10:] + hash[:10]
print(hex)```
I understand the slicing and the increment operations, but what I don't understand is the hash[] array. The modulo operations are completely arbitrary, and I know that for fact. Why are only hash[0] and hash[1] being considered? Is this just a crappy hash function?
2. I'm (absolutely positively 100%) sure I've seen this hash function before and likewise not understood. Now I get it. Prove that it's bad! The modulus operations result in some arbitrary manipulations roughly 5 of every 6 characters in the text to hash. I once cracked an exclusive or code as one of the challenges in a programming contest. It was easy for about everyone who entered the contest. The stirring and whatnot is necessary. Roughly the correct website. I translate to actual python as
Code:
```input='secret password'
# salt is random data per password, stored with the hashed password
# http://www.javacodegeeks.com/2012/02/introduction-to-strong-cryptography-p1.html
input+= 'salt'
key="Jonathan's awesome hash function"
input += key[:max(0,32-len(input)%32)]  # make the input length a multiple of 32
hash = [ord(c) for c in key]            # convert the characters to integers
for i in range(0,len(input),32):
block_32 = input[i:i+32]            # grab the next 32 characters
hash = [h^ord(c) for (h,c,) in zip(hash,block_32)] # exclusive or
if hash[0] % 2: # if odd change the data in a squirrely manner
hash = [(a+42)%256 for a in hash]
if hash[1] % 3: # stir the pot if hash[1] is not a multiple of 3
hash = hash[10:] + hash[:10]

print(('%2x'*32)%tuple(hash))```
3. #### The puzzle

Given the encryption function is exclusive or, and that the key is 7 characters long, decrypt this truly secret message:
Code:
``` 14 11  78  17  27  12 83  37   0   9  12 29   7
26 41   2  78  34  28 13  83  36  23  11  4   7
12 23 103  17   6   0 83   1  22  38  19 11  11
0 73  18  41   1  78 17  27  12  83  34  4  28
17 27  71  83 103  43  1  18  83  29  27 34  69
11  4   1  29  27 103 18  15  22  83  15 28  53
8  2   0   0  26  83 38  11  10  69  22  4   3
51 28  66  69  23   8  1  44  11  11  22  0  73
4 38  22  78  10   5 12   1 103  17   6  0  83
26  6  53   3  15   6 22  73  28  33  69 26  13
22 73  23  34   0  30 73  83   8  29  35 69  26
13 22  73  32  55  12 28  12   7  73  28 33  69
41 10  23  73   4  38 22  78  13  28  31 22  53
12  0   2  83   6   5 34  23  78  17  27 12  83
48  4  26   0   1  26 93 103  69  47  11 23  73
52 40   1  78  22  18  0  23 107  69  76 41  22
29 83  51  13  11  23 22  73  17  34  69  2  12
20  1   7 107  71  78  4  29  13  83  51 13  11
23 22  73   4  38  22 78   9  26  14  27 51  75
78 69  52   6  23 103 22  15  18  83  29 27  38
17 78  17  27  12  83 43  12   9  13   7 73   4
38 22  78   2  28   6 23 107  69  15  11 23  73
27 34  69  29   0   3  8   1  38  17  11  1  83
29 27  34  69   2  12 20   1   7 103   3 28  10
30 73   7  47   0  78  1  18  27  24  41  0  29
22 93  73  83   0  10 10  69  16   8  31 43   0
10 69   7   1  22 103  9   7   2  27  29 83 101
1 15  28  95  75  83 38  11  10  69   7  1  22
103  1  15  23  24   7 22  52  22  78  13 22  73
16 38   9   2   0  23 73  81  41  12   9 13   7
71 81 103  36   0   1 83  29  27  34  23 11  69
4  8   0 103   0  24  0  29   0  29  32 73  78
4 29  13  83  51  13 11  23  22  73   4 38  22
78  8  28  27  29  46 11   9 135 243 253  7  47
0 78   3  26  27   0 51  69  10   4  10 71 121```