task 9
This commit is contained in:
@@ -4,7 +4,7 @@ class Exercise00:
|
||||
STUDENT_NAME = "Eggert Jung"
|
||||
|
||||
def __init__(self, txt=""):
|
||||
self.__txt = txt[:17] + "..."
|
||||
self.__txt = txt
|
||||
|
||||
@staticmethod
|
||||
def deadline(formatstr):
|
||||
@@ -13,7 +13,7 @@ class Exercise00:
|
||||
|
||||
@property
|
||||
def txt(self):
|
||||
return self.__txt
|
||||
return self.__txt[:17] + "..."
|
||||
|
||||
def format(self, mode):
|
||||
if mode == "order":
|
||||
@@ -35,3 +35,42 @@ class Exercise00:
|
||||
ret = ret + "{} = {}".format(items[0], items[1]) + "\n"
|
||||
return ret[:-1]
|
||||
|
||||
def __str__(self):
|
||||
return b64_enc(self.__txt)
|
||||
|
||||
def b64_enc_map(index):
|
||||
if(index >= 0 and index < 26):
|
||||
return chr(index + 0x41) # A-Z
|
||||
elif(index >= 26 and index < 52):
|
||||
return chr(index + 0x61 - 26) # a-z
|
||||
elif(index >= 52 and index < 62):
|
||||
return chr(index + 0x30 - 52) # 0-9
|
||||
elif(index == 62):
|
||||
return '+'
|
||||
elif(index == 63):
|
||||
return '/'
|
||||
else:
|
||||
return '='
|
||||
|
||||
def b64_enc(str):
|
||||
res = ""
|
||||
|
||||
for c in [(str[i:i+3]) for i in range(0, len(str), 3)]:
|
||||
c = bytes(c, 'utf-8')
|
||||
bits = [-1,-1,-1,-1]
|
||||
try:
|
||||
bits[0] = (c[0] & 0xFC)>>2
|
||||
|
||||
bits[1] = ((c[0] & 0x03)<<4)
|
||||
bits[1] = bits[1] + ((c[1] & 0xF0)>>4)
|
||||
|
||||
bits[2] = ((c[1] & 0x0F)<<2)
|
||||
bits[2] = bits[2] + ((c[2] & 0xC0)>>6)
|
||||
|
||||
bits[3] = (c[2] & 0x3F)
|
||||
except IndexError:
|
||||
pass
|
||||
for i in range(4):
|
||||
res = res + b64_enc_map(bits[i])
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user