예제 #1
0
from hacker.bytestreams import substrings
from hacker.codes import BRAILLE
from hacker.decoder import decode

value = [
    ' . .  .     .  ..  .  . .  .      .  .     . .  .  .. .. .  ..  .  . .  .  .. .. .  ',
    '.. ..  .        . .  ..  . ..    .  .     .   .     .  .  . .  .  .  .   .  .     . ',
    '.              .  .   .    .        .     .  .  .. .     .     .     .     .        ',
]

result = decode(
    zip(substrings(value[0], 3), substrings(value[1], 3),
        substrings(value[2], 3)), lambda t: t[0][0:2] + t[1][0:2] + t[2][0:2],
    BRAILLE)
print(result)
예제 #2
0
value = 'fmpmfpmpp mmmpppfmmfppmpppff fmpppf pmfmffmpfmpp, fmpmfpmpp fmfpppmfffpmmpppfffmmmpp, mmmpppmpm mppfpmmpppffffmfmpmfpmffpppmfm mfffmm mpfppfpfffmpffmfmpfppppf'  # noqa

# To make decoding easier, we also make the puntuation take 3 characters
temp = decode(value, {' ': '   ', ',': ',,,'})

translation = {
    '   ': ' ',
    ',,,': ',',
    'fmp': 'T',
    'mfp': 'H',
    'mpp': 'E',
    'ppf': 'O',
    'mmm': 'a',
    'ppp': 'N',
    'fmm': 'S',
    'fpp': 'W',
    'pff': 'R',
    'mpm': 'D',
    'fmf': 'U',
    'pmf': 'L',
    'mff': 'I',
    'mpf': 'F',
    'fpm': 'V',
    'ffm': 'Y',
    'mfm': 'G',
}

result = decode(substrings(temp, 3), translation)
print(result)
예제 #3
0
    'Utah': 'UT',
    'Vermont': 'VT',
    'Virginia': 'VA',
    'Washington': 'WA',
    'West Virginia': 'WV',
    'Wisconsin': 'WI',
    'Wyoming': 'WY',
    # Districts, territories and possessions
    'American Samoa': 'AS',
    'District of Columbia': 'DC',
    'Federated States of Micronesia': 'FM',
    'Guam': 'GU',
    'Marshall Islands': 'MH',
    'Northern Mariana Islands': 'MP',
    'Palau': 'PW',
    'Puerto Rico': 'PR',
    'Virgin Islands': 'VI',
}
states = {value: key for key, value in states.items()}


def decode_substring(s):
    """
    Decode a substring of length 3
    The first 2 characters indicate a state, the third which letter in the state name to return
    """
    return states.get(s[:2])[ord(s[2]) - ord('a')]

result = decode(substrings(value, 3), decode_substring)
print(result)
예제 #4
0
from hacker.bytestreams import substrings

value = '751a6f1d3d5c3241365321016c05620a7e5e34413246660461412e5a2e412c49254a24'

key = ord('Y') ^ 0x75  # Key is only relevant for first character

result = ''
for s in substrings(value, 2):
    v = int(s, 16)
    result += chr(v ^ key)
    key = v

print(result)
예제 #5
0
from hacker.bytestreams import substrings

value = '00230211913108430050286091123267001446589042407200380634902253880050113189282402'

sum_lat: float = 0
sum_lon: float = 0
for s in substrings(value, 16):
    lat = int(s[:8]) / 1e6
    lon = int(s[8:]) / 1e6
    print(lat, lon)

    sum_lat += lat
    sum_lon += lon

print()
print(sum_lat / 5, sum_lon / 5)

# http://www.copypastemap.com/
# 0.230211	-91.310843	cross5	red	1	Point1
# 0.50286	-91.123267	cross5	red	2	Point2
# 0.144658	-90.424072	cross5	red	3	Point3
# 0.380634	-90.225388	cross5	red	4	Point4
# 0.501131	-89.282402	cross5	red	5	Point5

# DMS to DD conversion (seems to have little effect)
# 0.4419444	91.75083333333333
# 1.6277778	92.1075
# 1.5272222	91.83111111111111
# 0.8094444	91.86333333333333
# 1.1475  90.13388888888889
예제 #6
0
    'AUA': 'I',
    'ACA': 'T',
    'AAA': 'K',
    'AGA': 'R',
    'AUG': 'M',
    'ACG': 'T',
    'AAG': 'K',
    'AGG': 'R',
    'GUU': 'V',
    'GCU': 'a',
    'GAU': 'D',
    'GGU': 'G',
    'GUC': 'V',
    'GCC': 'a',
    'GAC': 'D',
    'GGC': 'G',
    'GUA': 'V',
    'GCA': 'a',
    'GAA': 'E',
    'GGA': 'G',
    'GUG': 'V',
    'GCG': 'a',
    'GAG': 'E',
    'GGG': 'G',
}

assert value[0:3] == 'AUG'  # The initiation site for encoding

result = decode(substrings(value[3:], 3), translation)
print(result)
예제 #7
0
def hex_str_to_color_name(val: str) -> str:
    tup: Tuple[int, ...] = tuple(map(base16, substrings(val[1:], 2)))
    return COLOR_NAMES[tup]