aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-11-16 08:12:57 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-11-16 08:12:57 -0500
commit1eb5bfb633a5f3874e74242576f5fdbbe5bccbf4 (patch)
treeac72719d99fd104eae70a068b0dea743a02b4276
parent8eb41720f151d20f13d7316d30cd8a02c8664e42 (diff)
added library abstraction for conversion
-rw-r--r--final/rsautils.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/final/rsautils.py b/final/rsautils.py
new file mode 100644
index 0000000..236571c
--- /dev/null
+++ b/final/rsautils.py
@@ -0,0 +1,29 @@
+def list2int(arr,base,endian="little"):
+ if endian == "big":
+ arr.reverse()
+ out = 0
+ for num in arr:
+ out *= base
+ out += num
+ return out
+
+def int2list(num,base,endian="little"):
+ arr = []
+ while num > 0:
+ arr.append(num%base)
+ num = num//base
+ if endian == "little":
+ arr.reverse()
+ return arr
+
+def int2string(num):
+ return ''.join([chr(charval) for charval in int2list(num,128)])
+
+def string2int(string,endian="little"):
+ return list2int([ord(char) for char in string],128,endian=endian)
+
+def int2base64(num):
+ return ''.join([chr(charval+32) for charval in int2list(num,64)])
+
+def base642int(code):
+ return list2int([ord(char)-32 for char in code],64)