/usr/lib/python2.7/dist-packages/sagenb/notebook/compress/BaseConvert.py is in python-sagenb 1.0.1+ds1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # -*- coding: utf-8 -*
# BaseConvert class,
# converts an unsigned base 10 integer to a different base and vice versa.
# ______________________________________________________________
# BaseConvert
# |
# |________ constructor(newBase:string)
# | uses newBase string var for convertion
# | [i.e. "0123456789abcdef" for an hex convertion]
# |
# |________ toBase(unsignedInteger:uint):string
# | return base value of input
# |
# |________ fromBase(baseString:string):uint
# return base 10 integer value of base input
# --------------------------------------------------------------
# @Compatibility >= Python 2.3
# @Author Andrea Giammarchi
# @Site http://www.devpro.it/
# @Date 2006/06/05
# @Version 1.0
# @License GNU General Public License (GPL)
class BaseConvert:
__base = ""
__baseLength = 0
def __init__(self, __base):
self.__base = __base
self.__baseLength = len(__base)
def toBase(self, num):
module = 0
result = ""
while num != 0:
module = num % self.__baseLength
result = self.__base[module] + result
num = int((num - module) / self.__baseLength)
if result == "":
result = self.__base[0]
return result
def fromBase(self, str):
pos = 0
strLen = len(str) - 1
result = 0
while pos < strLen:
result = result + (pow(self.__baseLength, strLen - pos) * self.__base.find(str[pos]))
pos = pos + 1
if strLen >= 0:
result = result + self.__base.find(str[pos])
return result;
|