-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAll.py
33 lines (30 loc) · 873 Bytes
/
All.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import random
from Huffman import HuffmanCoding
from Convolutional import Convolutional
import binascii
def noise(input):
output = ''
for i in range(0, len(input)):
r = random.uniform(0, 1)
if(r < 0.1):
output += str(1 - int(input[i]))
else:
output += (input[i])
return output
def main() :
h = HuffmanCoding()
c = Convolutional()
input = "negarmirgati"
print('input', input)
hEncoded = h.encode(input)
print('huffman coded', hEncoded)
cEncoded = c.encode(hEncoded)
print('Convolutional encoded', cEncoded)
inputWithNoise = noise(cEncoded)
print('noise added', inputWithNoise)
cDecoded = c.decode(inputWithNoise)
print('convolutional decode', cDecoded)
hDecoded = h.decode(cDecoded)
print('huffman decode', hDecoded)
if __name__== "__main__":
main()