PKiN)\UmyFbase/__init__.py""" Change to/from any base you like Example: from myFbase import MyFbase mfb = MyFbase('abc') print(mfb.encode(8)) # cc print(mfb.decode('cc')) # 8 """ from .myfbase import MyFbase __version__ = "0.1.0" PK;NV myFbase/myfbase.pyclass MyFbase(object): def __init__(self, base: str): super(MyFbase, self).__init__() self.base = [c for c in base] self._numeric_base = len(self.base) if len(set(self.base)) != len(self.base): raise ValueError("Your base has duplicate elements.") def encode(self, decimal_number: int) -> str: """ >>> m.encode(0) 'a' >>> m.encode(1) 'b' >>> m.encode(2) 'c' >>> m.encode(3) 'ba' """ if decimal_number < 0: raise ValueError("Can convert only positive integers") if decimal_number == 0: return self.base[0] digits = [] while decimal_number > 0: digits.append(decimal_number % self._numeric_base) decimal_number //= self._numeric_base return "".join([self.base[e] for e in digits[::-1]]) def decode(self, code: str) -> int: """ >>> m.decode('a') 0 >>> m.decode('b') 1 >>> m.decode('c') 2 >>> m.decode('ba') 3 """ out = 0 reversed_code = code[::-1] for index, char in enumerate(reversed_code, start=0): out += self.base.index(char) * (self._numeric_base ** index) return out if __name__ == "__main__": import doctest doctest.testmod(extraglobs={"m": MyFbase("abc")}) PKB{M77myFbase-0.1.0.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2018 victor141516 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!Hd BUcmyFbase-0.1.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!H zL) myFbase-0.1.0.dist-info/METADATAOO@)& phKD1=oC'[mhyogJp%$SKN-4hJ6Դ),**KQlU d~W圶iUM1%#gN.O33#Uʤ4CשXT3Tv΂C :y~+ip7~lW2V[IuDD|&WQ-2W5x\}qZ!%Ka`L>ʿ쏿aWxc.5o:}hoҎ_&՞M~M6TP$K&nUheͨ%<_sɯu7T$aioհvf nG+.w򨢾ElDӡ17"chTkWllg\m6Ax:o"eZ#}:9?PKiN)\UmyFbase/__init__.pyPK;NV myFbase/myfbase.pyPKB{M77myFbase-0.1.0.dist-info/LICENSEPK!Hd BUcJ myFbase-0.1.0.dist-info/WHEELPK!H zL)  myFbase-0.1.0.dist-info/METADATAPK!H֝+2(d myFbase-0.1.0.dist-info/RECORDPK