forked from kalmar/DALGLI0
Zaktualizuj 'hw3.py'
zmiana outputu
This commit is contained in:
parent
14d223b47b
commit
c93bc4b37e
12
hw3.py
12
hw3.py
@ -1,5 +1,6 @@
|
||||
from sys import argv
|
||||
from fractions import gcd
|
||||
from ast import literal_eval
|
||||
|
||||
class Polynomial():
|
||||
def __init__(self, lst, mod):
|
||||
@ -112,7 +113,7 @@ def to_bin(x):
|
||||
if len(data) < 8:
|
||||
data = str(0) + data
|
||||
else:
|
||||
data.replace(data[0], '')
|
||||
data = data[1:]
|
||||
return data
|
||||
|
||||
def to_ascii_val(lst):
|
||||
@ -120,6 +121,7 @@ def to_ascii_val(lst):
|
||||
for i in range(len(lst)):
|
||||
if lst[i] == 1:
|
||||
sum += 2**(7-i)
|
||||
|
||||
return chr(sum)
|
||||
|
||||
def data():
|
||||
@ -157,16 +159,18 @@ def check(m):
|
||||
|
||||
def main():
|
||||
global m
|
||||
m = list(argv[1])
|
||||
mode = argv[2] # flagi -e -d (encode, decode)
|
||||
m = list(argv[2])
|
||||
mode = argv[1] # flagi -e -d (encode, decode)
|
||||
if mode == '-e':
|
||||
res = fcs(m)
|
||||
fcs_ch1 = to_ascii_val(res[:8])
|
||||
fcs_ch2 = to_ascii_val(res[8:])
|
||||
m.append(fcs_ch1)
|
||||
m.append(fcs_ch2)
|
||||
print(''.join(m))
|
||||
print(m)
|
||||
elif mode == '-d':
|
||||
to_check = literal_eval(argv[3])
|
||||
m += to_check
|
||||
print(check(m))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user