usr bin env python coding utf-8 import math ENG RUS ASCII 255 alphabet

  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
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
ENG=1
RUS=0
ASCII=255
alphabet = [u"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",
u"ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
def getcode(letter,language):
if language == ASCII:
return ord(code)
i = 0
for search in alphabet[language]:
if letter == search:
return i
i = i+1
def getletter(code,language):
if language == ASCII:
return chr(code)
if (code == None) or (code > len(alphabet[language])-1):
print code
return " "
return alphabet[language][code]
LEFT = 0
RIGHT = 1
BIG = 1
LITTLE = -1
msg=[
1,0,0,1,
1,0,1,0,
0,0,0,0,
1,0,1,1,
1,0,0,1,
0,1,0,0,
0,1,1,0,
1,0,1,1,
1,0,0,1,
1,1,0,1,
1,1,0,0,
1,0,0,1,
1,1,1,0,
0,0,0,1,
1,1,0,1,
0,1,1,0,
1,0,0,1,
0,0,0,0,
1,0]
def array_to_value(array,endian):
size = len(array)
value = 0
i = 0
for element in apply(xrange,(0,size) if (endian > 0) else (size-1, -1, endian)):
value = value + (2**i)*array[element]
i = i + 1
return value
def array_to_subs(array,sub_size,endian):
size = len(array)
elems = int(size/sub_size)
if (size%sub_size != 0):
elems = elems+1
subs = [None for i in xrange(0, elems)]
for i in xrange(0,elems):
subs[i] = array[i*sub_size:i*sub_size+sub_size] if (endian>0) else array[-i*sub_size-sub_size:-i*sub_size]
return subs
def bitsize(val):
return int(math.floor(math.log(val,2))+1)
# print array_to_subs(msg, 4, LITTLE)
# print bitsize(len(alphabet[RUS]))
# print bitsize(len(alphabet[ENG]))
# for abc in [ENG, RUS]:
# for top_endian in [BIG,LITTLE]:
# for bottom_endian in [BIG,LITTLE]:
# string = ""
# for letter in array_to_subs(msg,bitsize(len(alphabet[abc])),top_endian):
# string = string + getletter(int(array_to_value(letter, bottom_endian)) % len(alphabet[abc]), abc)
# print string
# for subs in [8]:
# for top_endian in [BIG,LITTLE]:
# for bottom_endian in [BIG,LITTLE]:
# for offset in xrange(0,127):
# string = ""
# for letter in array_to_subs(msg,subs,top_endian):
# string = string + chr(((array_to_value(letter, bottom_endian) + offset)+ ord(" ")) % 128 )
# print string
# for sub_size in xrange(1,9):
# max_l = -1
# min_l = 99999999
# for letter in array_to_subs(msg,sub_size,BIG):
# max_l = max(max_l, array_to_value(letter, BIG))
# min_l = min(min_l, array_to_value(letter, BIG))
# print str(sub_size) + ": " + str(max_l - min_l) + " " + str(min_l) + "-" + str(max_l)
one = 0
zero = 0
for item in msg:
if item == 0:
zero = zero + 1
if item == 1:
one = one + 1
print "0: " + str(zero) + " 1: " + str(one)
# group = 26
# for offset in xrange(0,26):
# result = ""
# for letter in array_to_subs(msg,4,BIG):
# result = result + getletter(int(array_to_value(letter, BIG) + offset) % 26, ENG)
# print result
value = array_to_value(msg,LITTLE)
print value