Procházet zdrojové kódy

add word_generater_py3.py

duh@133.cn před 5 roky
rodič
revize
80abc50759

+ 32 - 0
pyproject/SSHManager/local_generater/word_generater_py3.py

@@ -0,0 +1,32 @@
+# conding: utf-8
+import string
+import base64
+import random
+import sys
+
+def encodestr(s):
+    salt1 = ''.join(random.sample(string.ascii_letters + string.digits, 5))
+    salt2 = ''.join(random.sample(string.ascii_letters + string.digits, 8))
+    ens = ''
+    sens = str(base64.b64encode(s.encode('utf-8')), 'utf-8').strip()
+    sens = sens.strip('=')
+    for num, word in enumerate(sens):
+        if num == 0:
+            ens += salt1
+        if num == len(sens) - 4 and len(sens) > 10:
+            ens += salt2
+        ens += word
+    return ens
+
+
+def decodestr(s):
+    dns = s[5:].replace(s[-12:-4],'') + '=='
+    return str(base64.b64decode(dns.encode('utf-8')),'utf-8')
+
+if __name__ == "__main__":
+    if len(sys.argv) != 3:
+        print("usage: word_generater.py [decodestr]/[encodestr] [string]")
+    if sys.argv[1] == "decode" :
+        print(decodestr(sys.argv[2]))
+    if sys.argv[1] == "encode" :
+        print(encodestr(sys.argv[2]))