Está en la página 1de 3

Sergio Gonzales

cs313
huffman and hamming

encryption

MESSAGE TO ENCRYPT: "this is the zodiac speaking"

the break down:


t= 2/24
h= 2/24
i= 3/24
s= 2/24
e= 2/24
z= 1/24
o= 1/24
d= 1/24
a= 2/24
c= 1/24
p= 1/24
k= 1/24
n= 1/24
space = 3/24
24/24 test for correctness a/b if a = b frequency is correct
TREE CLIMBING:
build a tree from the bottom up starting with lowest values on bottom left.

2/24
0 1
1/24 1/24
example
z o

build complete tree

24/24
0 1

8/24
16/24
0 1
1
4/2 0
4/24
4 8/2 8/24
1 4
0 1 1
0 1 0
2/24 0
2/24 2/24 2/24 5/24 3/24
4/24 4/24
1 1 1 0
0 0 0 1 0 1 0 1 1
0
1/24 1/24 1/24 1/24 1/24 1/24 2/24 2/24 2/24 2/24 2/24 3/24
1/24 1/24
z o d c p n e a
k g t h s
encode the letters by moving down the tree.
t= 1000
h= 1001
i= 1101
s= 1100
e= 1010
z= 0000
o= 0001
d= 0010
a= 1011
c= 0011
p= 0100
k= 0101
n= 0110
g= 0111
space = 111

now encode the text use the coded letters


this is the zodiac speaking =
10001001110111001111101110011110001001101011100000001001011011011001111111000100101010110101110101100111

decryption:
to decrypt the message we just use the key to find the patterns inside the code
1000100111011100
to find the pattern we break it apart.
1000 1001 1101 1100
t h i s
hamming error handling
first we take our encoded phase

this is the zodiac speaking =


10001001110111001111101110011110001001101011100000001001011011011001111111000100101010110101110101100111
then we create our check bit table.
break the code up into four bit sections
C are the check bits are the points with only one bit.
0 0 0 0 0 0 0
1 2 3 4 5 6
0 0 0 1 1 1 1
1000 1001 1101 1100 1111 1011 1001 1110 0010 0110
0 1 1 0 0 1 1
1011 1000 0000 1001 0110 1101 1001 1111 1100 0100
1 0 1 0 1 0 1
1010 1011 0101 1101 0110 0111
C1 C2 D1 C3 D2 D3 D4

0 0 0 0 0 0 0
0 0 0 1 1 1 1
0 1 1 0 0 1 1
1 0 1 0 1 0 1
C1 C2 D1 C3 D2 D3 D4
next we need to add the data
1 0 0 0
once data is in we need to find the check bits.
looking at the table we see above C1 is a one and looking across from that one
we see that D1, D2, D4 also have ones,
this tells us that the value of C1 is equal to the xor of the other values.
0 0 0 0 0 0 0 C1= D1 xor D2 xor D4
0 0 0 1 1 1 1 C1 = 1 xor 0 xor 0
0 1 1 0 0 1 1 C1 = 1
1 0 1 0 1 0 1
C1 C2 D1 C3 D2 D3 D4 we continue for all check bits and perform this for all sections of four
the hamming for sections 1-6 is 1110000 0011001 1010101 1111100 1111111 0110011
1 1 1 0 0 0 0
decoding a hamming transmission is the reverse except that hamming provides error correction.
for example let assume we received 1010000 0001001

0 0 0 0 0 0 0 first set up the table


0 0 0 1 1 1 1 place in the first section of code
0 1 1 0 0 1 1 now we xor all values for C1 including C1 and the result should be zero
1 0 1 0 1 0 1
like this
C1 C2 D1 C3 D2 D3 D4 A1 = C1 xor D1 xor D2 xor D4
1 0 1 0 0 0 0 A1 = 1 1 0 0
A1 = 0

A2 = C2 xor D1 xor D3 xor D4


A2 = 1

A3 = C3 xor D2 xor D3 xor D4


A3 = 0
to check for error we read up from the bottom, 0 1 0 which in binary equal 2
0 0 0 0 0 0 0
so the error is in position 2 and is easily fixed by flipping the bit then remove the check bits.
0 0 0 1 1 1 1
the correct code being 1000
0 1 1 0 0 1 1
1 0 1 0 1 0 1
the next section we repeat the steps
C1 C2 D1 C3 D2 D3 D4 A1 = 1
A2 = 1
0 1 0 1 0 0 1 A3 = 0
011 = 3 error in position 3 extracted code is 1001

También podría gustarte