diff --git a/bigrandom/answer.py b/bigrandom/answer.py index cb5fee4..af887c6 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -1,16 +1,32 @@ class BigRandom: def __init__(self): - self.data = "data.txt" - # add attributes if you need more + self.data = "data.txt" def answer(self): + noh = 0 # variable to store number of hashtag - # ommiting line number's hashtag + # ommiting line number's hashtag suc = 0 # variable to store sum of character's code in ascii, - # ommiting line number and its hashtag + # ommiting line number and its hashtag # your algorithm + + self.data = open("data.txt", "r") + noh, suc = 0, 0 + for line in self.data.readlines(): + noh = noh + len([x for x in line if x == '#']) #______ count of '#' + suc = suc + sum([ord(x) for x in line]) #_____________ sum of asciis of all chars + + + numbs = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 + + self.data.close() # close data stream - return (noh,suc) + # ord('#') * 10000 _________________ sum of asciis of first '#' in each row + # sum([ord(x) for x in nomor]) _____ sum of asciis of numbs + return (noh - 10000, suc - (ord('#') * 10000 + sum([ord(x) for x in numbs]))) - # add methods if you need more \ No newline at end of file +# instantiation +big = BigRandom() +a, b = big.answer() +print(a, b) \ No newline at end of file diff --git a/caesar/answer.py b/caesar/answer.py index 0d85db4..5b239af 100644 --- a/caesar/answer.py +++ b/caesar/answer.py @@ -4,10 +4,15 @@ def __init__(self): # add attributes if you need more def answer(self): - key = 0 # variable to store the key + key = 0 # your algorithm - + self.ciphertext = open("ciphertext.txt", "r+") + msg = ''.join([chr(ord(x) - key) for x in str(self.ciphertext.readlines())]) # ____ decripting @return decripted string + print("Hasil decrypt dengan key %d adalah \n %s" % (key, msg)) # __________________ printing out + self.ciphertext.close() # _________________________________________________________ close data stream return (key) - # add methods if you need more \ No newline at end of file +# instantiation +csr = Caesar() +print(csr.answer()); \ No newline at end of file