summaryrefslogtreecommitdiff
path: root/numpy/f2py/lib/nary.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/f2py/lib/nary.py')
-rw-r--r--numpy/f2py/lib/nary.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/f2py/lib/nary.py b/numpy/f2py/lib/nary.py
new file mode 100644
index 000000000..948672b8c
--- /dev/null
+++ b/numpy/f2py/lib/nary.py
@@ -0,0 +1,32 @@
+"""
+nary - convert integer to a number with an arbitrary base.
+"""
+
+__all__ = ['nary']
+
+_alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+def _getalpha(r):
+ if r>=len(_alphabet):
+ return '_'+nary(r-len(_alphabet),len(_alphabet))
+ return _alphabet[r]
+
+def nary(number, base=64):
+ """
+ Return string representation of a number with a given base.
+ """
+ if isinstance(number, str):
+ number = eval(number)
+ n = number
+ s = ''
+ while n:
+ n1 = n // base
+ r = n - n1*base
+ n = n1
+ s = _getalpha(r) + s
+ return s
+
+def encode(string):
+ import md5
+ return nary('0x'+md5.new(string).hexdigest())
+
+#print nary(12345124254252525522512324,64)